procedure TMainForm.Button1Click(Sender: TObject);
var WebSite,WebServer,WebRoot,VDir:Variant;
VDirExists:Boolean;
begin
try WebSite:=CreateOleObject('IISNamespace'); except Dialogs.MessageDlg('本机可能没有安装IIS系统,接口读取错误!',mtError,[mbOK],0); Exit; end;
WebSite:=WebSite.GetObject('IIsWebService', 'localhost/w3svc');
WebServer:=WebSite.GetObject('IIsWebServer', '1');
WebRoot:=WebServer.GetObject('IIsWebVirtualDir', 'Root');
try VDir:=WebRoot.GetObject('IIsWebVirtualDir','Report'); VDirExists:=True; except VDirExists:=False; end;
if VDirExists and (Dialogs.MessageDlg('此虚拟目录已经存在,是否进行属性变更?',mtConfirmation, [mbYes, mbNo], 0)<>mrYes) then Exit;
if not VDirExists then VDir:=WebRoot.Create('IIsWebVirtualDir', 'Report');
VDir.Path:='d:/report';
VDir.AccessRead:=True; //读取
VDir.AccessWrite:=False; //写入
VDir.EnableDirBrowsing:=False; //目录浏览
VDir.AccessSource:=True; //脚本资源访问
VDir.AccessScript:=True; //脚本
VDir.AccessExecute:=True; //可执行
VDir.SetInfo;
try
VDir:=WebRoot.GetObject('IIsWebVirtualDir','Report');
Dialogs.MessageDlg('虚拟目录信息写入成功!',mtInformation,[mbOK],0);
except
Dialogs.MessageDlg('虚拟目录信息写入失败!',mtError,[mbOK],0);
end;
end;