我在网上找了一个创建web虚拟目录的文章其中有三个例子,但只有一个能运行,但没有删除虚拟目录代码?
先引入类型库(Project|Import Type Library)adsiis.dll、iisext.dll和activeds.tlb
新建一个单元,声明
unit ActiveDs;
interface
function ADsGetObject(const PathName: WideString; const GUID: TGUID; out I: IUnknown): HRESULT; stdcall;
implementation
function ADsGetObject; external 'activeds.dll' name 'ADsGetObject';
end.执行代码如下:
uses 
ComObj,IISOle_TLB, ActiveDs_TLB; procedure TForm1.MakeVirtualDir(path, vdname: string); 
var 
Disp: IDispatch; begin 
Disp := CreateOleObject('IISNamespace'); 
Disp := (Disp as IISNamespace).GetObject('IIsWebService', 'localhost/w3svc'); 
Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1'); 
Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root'); 
Disp := (Disp as IADsContainer).Create('IIsWebVirtualDir',vdname); 
(Disp as IADs).Put('AccessRead', 'True'); 
(Disp as IADs).Put('Path', path); 
(Disp as IADs).SetInfo; 
end;
procedure TForm1.DeleteVirtualDir(vdname:string);
var
Disp: IDispatch;
begin
try
        Disp := CreateOleObject('IISNamespace');
        Disp := (Disp as IISNamespace).GetObject('IIsWebService', 'localhost/w3svc');
        Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');
        Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');
        Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
 except
     //messagebox(application.Handle,pchar('无法删除。'),'提示',MB_ICONStop);
 end;
end;我现在可以MakeVirtualDir过程新建虚拟目录,但是删除语句:
 Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
这句语句编译报错:
[Error] Unit1.pas(1017): Incompatible types: 'procedure, untyped pointer or untyped parameter' and 'IDispatch'
请高手指点,高分相送。

解决方案 »

  1.   

    删除一个虚拟目录
    脚本的代码,没有时间给你翻译到delphi了,你自己翻译吧。
    都是使用了adsi,和你使用IIS的原理是一样的。
    <%on error resume nextsComputer ="localhost"
    sPhyDir = "c:\dina\adsi"
    sVirDir = "ADSITest"'Get Default Web Site Object
    set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
    Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
    set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
    Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
    %>
      

  2.   

    我在asp的VbSript中找到例子, Delphi怎样实现?
    删除一个虚拟目录在这个例子中,你将学习到如何删除一个虚拟目录。当建立一个对象时,你必须有它的父对象。这
    个真理也同样适用于删除。例七表明了如何做。
    Example 7
    <%
    on error resume nextsComputer ="localhost"
    sPhyDir = "c:\dina\adsi"
    sVirDir = "ADSITest"'Get Default Web Site Object
    set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
    Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
    set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
    Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
    %>  我在大富翁上也发了帖子。
    谢谢搂上的前辈指点,我就是这样翻译的代码编译就是不通过。
    在线等待高手,我想只是看一个删除的小例子。
      

  3.   


    <%
    on error resume nextsComputer ="localhost"
    sPhyDir = "c:\dina\adsi"
    sVirDir = "ADSITest"'Get Default Web Site Object
    set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
    Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
    set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
    Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
    %>