请问:如何用Delphi写一个程序,可以创建,删除IIS的虚拟目录??多谢!!(100分)

  • 主题发起人 主题发起人 popboy
  • 开始时间 开始时间
P

popboy

Unregistered / Unconfirmed
GUEST, unregistred user!
能够用Delphi实现在IIS里创建,删除虚拟目录吗?如何实现??<br>用ASP可以实现吗??<br><br><br>多谢!!
 
先引入类型库(Project|Import Type Library)adsiis.dll、iisext.dll和activeds.tlb<br>新建一个单元,声明<br>unit ActiveDs;<br>interface<br>&nbsp; function ADsGetObject(const PathName: WideString; const GUID: TGUID; out I: IUnknown): HRESULT; stdcall;<br>implementation<br>&nbsp; function ADsGetObject; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;external 'activeds.dll' name 'ADsGetObject';<br>end.<br><br>方法一(参照C++)、<br>var<br>&nbsp; I: IADsContainer;<br>&nbsp; ADs: IADs;<br>begin<br>&nbsp; if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then<br>&nbsp; begin<br>&nbsp; &nbsp; ADs := IADs(I.GetObject('IIsWebServer', '1'));<br>&nbsp; &nbsp; ShowMessage(ADs.ADsPath);<br>&nbsp; &nbsp; if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ADs := IADs(I.GetObject('IIsWebVirtualDir', 'Root'));<br>&nbsp; &nbsp; &nbsp; ShowMessage(ADs.ADsPath);<br>&nbsp; &nbsp; &nbsp; if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ADs := IADs(I.Create('IIsWebVirtualDir', 'DelphiTest'));<br>&nbsp; &nbsp; &nbsp; &nbsp; ADs.Put('AccessRead', 'True');<br>&nbsp; &nbsp; &nbsp; &nbsp; ADs.Put('Path', 'c:/Temp');<br>&nbsp; &nbsp; &nbsp; &nbsp; ADs.SetInfo;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>方法二(使用接口)、<br>procedure TForm3.BitBtn4Click(Sender: TObject);<br>var<br>&nbsp; Disp: IDispatch;<br>begin<br>&nbsp; Disp := IISNamespace1.GetObject('IIsWebService', 'localhost/w3svc');<br>&nbsp; Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');<br>&nbsp; Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');<br>&nbsp; Disp := (Disp as IADsContainer).Create('IIsWebVirtualDir', 'DelphiADSITest');<br>&nbsp; (Disp as IADs).Put('AccessRead', 'True');<br>&nbsp; (Disp as IADs).Put('Path', 'c:/ADSITest');<br>&nbsp; (Disp as IADs).SetInfo;<br>end;<br><br>方法三(使用Variant,就是类似VB和ASP的方法)、<br>procedure TForm2.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; WebSite, WebServer, WebRoot, VDir: Variant;<br>begin<br>&nbsp; WebSite := CreateOleObject('IISNamespace');<br>&nbsp; WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc');<br>&nbsp; WebServer := WebSite.GetObject('IIsWebServer', '1');<br>&nbsp; WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');<br>&nbsp; VDir := WebRoot.Create('IIsWebVirtualDir', 'VariantTest');<br>&nbsp; VDir.AccessRead := True;<br>&nbsp; VDir.Path := 'C:/Test';<br>&nbsp; VDir.SetInfo;<br>end;<br><br><br><br><br>
 
3.<br>WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc');<br><br>object 不能reference<br>2.<br>&nbsp;Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');<br><br>系统不知道IADsContainer是什么东东<br><br>1.<br><br>var<br>&nbsp; I: IADsContainer;<br>&nbsp; ADs: IADs;<br>系统不知道IADsContainer是什么东东<br>
 
如果操作IIS 的FTP怎么办呢??
 
接受答案了.
 
后退
顶部