先引入类型库(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.方法一(参照C++)、
var
  I: IADsContainer;
  ADs: IADs;
begin
  if ADsGetObject(’IIS://localhost/w3svc’, IID_IADsContainer, IUnknown(I)) = S_Ok then
  begin
    ADs := IADs(I.GetObject(’IIsWebServer’, ’1’));
    ShowMessage(ADs.ADsPath);
    if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
    begin
      ADs := IADs(I.GetObject(’IIsWebVirtualDir’, ’Root’));
      ShowMessage(ADs.ADsPath);
      if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
      begin
        ADs := IADs(I.Create(’IIsWebVirtualDir’, ’DelphiTest’));
        ADs.Put(’AccessRead’, ’True’);
        ADs.Put(’Path’, ’c:Temp’);
        ADs.SetInfo;
      end;
    end;
  end;
end;方法二(使用接口)、
procedure TForm3.BitBtn4Click(Sender: TObject);
var
  Disp: IDispatch;
begin
  Disp := IISNamespace1.GetObject(’IIsWebService’, ’localhost/w3svc’);
  Disp := (Disp as IADsContainer).GetObject(’IIsWebServer’, ’1’);
  Disp := (Disp as IADsContainer).GetObject(’IIsWebVirtualDir’, ’Root’);
  Disp := (Disp as IADsContainer).Create(’IIsWebVirtualDir’, ’DelphiADSITest’);
  (Disp as IADs).Put(’AccessRead’, ’True’);
  (Disp as IADs).Put(’Path’, ’c:ADSITest’);
  (Disp as IADs).SetInfo;
end;方法三(使用Variant,就是类似VB和ASP的方法)、
procedure TForm2.BitBtn1Click(Sender: TObject);
var
  WebSite, WebServer, WebRoot, VDir: Variant;
begin
  WebSite := CreateOleObject(’IISNamespace’);
  WebSite := WebSite.GetObject(’IIsWebService’, ’localhost/w3svc’);
  WebServer := WebSite.GetObject(’IIsWebServer’, ’1’);
  WebRoot := WebServer.GetObject(’IIsWebVirtualDir’, ’Root’);
  VDir := WebRoot.Create(’IIsWebVirtualDir’, ’VariantTest’);
  VDir.AccessRead := True;
  VDir.Path := ’C:Test’;
  VDir.SetInfo;
end;

解决方案 »

  1.   

    40Star:你说的三个方法我都试了第一种和我做的一样,还是没有创建应用程序名
    第二种:提示IISNamespace1.找来到
    第三种:运行后出错,Variant没有提供提口。
      

  2.   

    钱几天刚做过:(网友转载:测试通过)function ADsGetObject(const PathName: WideString; const GUID:TGUID; out I: IUnknown): HRESULT; stdcall;external 'activeds.dll' name 'ADsGetObject';
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Disp: IDispatch;
    begin
            Disp := IISNamespace1.GetObject('IIsWebService', 'localhost/w3svc');
            Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');
            Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');
            Disp := (Disp as IADsContainer).Create('IIsWebVirtualDir', 'DelphiADSITest');
            Disp as IADs).Put('AccessRead', 'True');
            Disp as IADs).Put('Path', 'c:\ADSITest');
            Disp as IADs).SetInfo;
    end;
      

  3.   

    Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots]
    "/"="c:\\inetpub\\wwwroot,,201"
    "/Scripts"="c:\\inetpub\\scripts,,204"
    "/IISAdmin"="C:\\WINNT\\System32\\inetsrv\\iisadmin,,5201"
    "/IISSamples"="c:\\inetpub\\iissamples,,201"
    "/MSADC"="c:\\program files\\common files\\system\\msadc,,205"
    "/IISHelp"="c:\\winnt\\help\\iishelp,,201"
    "/Webpub"="C:\\Inetpub\\webpub,,201"
    "/mp3"="F:\\song,,201"
    "/Printers"="C:\\WINNT\\web\\printers,,201"
    "/aaaaaaaaa"="C:\\Documents and Settings\\jiangxk\\×ÀÃæ,,201"
      

  4.   

    IISNamespace1
    这是什么,总是提示没找到这个。