用过php的应该知道,php发行时,带有一个php-x.x.x-installer.exe,可以帮你配置iis
我想知道这是怎么实现的,请大富翁们不吝赐教!

解决方案 »

  1.   

    参考资料:大富翁论坛第468148号贴子                                            }
    {参考资料:2000年7月份MSDN中IIsWebVirtualDir                                   }
    {------------------------------------------------------------------------------}
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ComObj, IISOle_TLB, ActiveDs_TLB;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
      private
        { Private declarations }
        function CreateIISVirtualPath(MapPath:String;Path:String):Boolean;
        function SetIISRootPathParam:Boolean;
        function KillIISPath(MapPath:String):Boolean;
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      function ADsGetObject(const PathName: WideString; const GUID: TGUID; out I: IUnknown): HRESULT; stdcallimplementationfunction ADsGetObject;external 'activeds.dll' name 'ADsGetObject'{$R *.DFM}function TForm1.CreateIISVirtualPath(MapPath:String;Path:String):Boolean;
    var
     I: IADsContainer;
     ADs: IADs;
    begin
     Result:=false;
     try
      if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
       begin
        ADs := IADs(I.GetObject('IIsWebServer','1'));
        i:=ADs as IADsContainer;
        ADs := I.GetObject('IIsWebVirtualDir','Root') as IADs;
        i:=ADs as IADsContainer;
        ADs := I.Create('IIsWebVirtualDir',MapPath) as IADs;
        ADs.Put('AccessRead','True');
        ADs.Put('AccessScript','True');
        ADs.Put('AccessExecute','True');
        file://modify by liguang in 2001-7-8 comeback from shengzhen
        file://if operating system is WINDOWS NT4.0+IIS4.0 then this call is error
        ADs.Put('AccessSource','True');
        ADs.Put('Path',Path);
        ADs.SetInfo;
        Result:=true;
       end;
     except
     end;
    end;function TForm1.SetIISRootPathParam:Boolean;
    var
     I: IADsContainer;
     ADs: IADs;
    begin
     Result:=false;
     try
      if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
       begin
        ADs := IADs(I.GetObject('IIsWebServer','1'));
        i:=ADs as IADsContainer;
        ADs := I.GetObject('IIsWebVirtualDir','Root') as IADs;
        ADs.Put('AccessRead','True');
        ADs.Put('AccessScript','True');
        ADs.Put('AccessExecute','True');
        ADs.Put('AccessSource','True');
        ADs.SetInfo;
        Result:=true;
       end;
     except
     end;
    end;function TForm1.KillIISPath(MapPath:String):Boolean;
    var
     I: IADsContainer;
     ADs: IADs;
    begin
     Result:=false;
     if MapPath='Root' then
      exit;
     try
      if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
       begin
        ADs := IADs(I.GetObject('IIsWebServer','1'));
        i:=ADs as IADsContainer;
        ADs := I.GetObject('IIsWebVirtualDir','Root') as IADs;
        i:=ADs as IADsContainer;
        ADs := I.GetObject('IIsWebVirtualDir',MapPath) as IADs;
        i.Delete(ADs.Get_Schema,ADs.get_Name);
        Result:=true;
       end;
     except
     end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     if CreateIISVirtualPath('WebUser','E:\VC')=true then
      MessageBox(GetforegroundWindow,'建立成功!','提示信息',MB_OK)
     else
         MessageBox(GetforegroundWindow,'建立失败!','提示信息',MB_OK);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
     if SetIISRootPathParam=true then
      MessageBox(GetforegroundWindow,'修改成功!','提示信息',MB_OK)
     else
         MessageBox(GetforegroundWindow,'修改失败!','提示信息',MB_OK);
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
     if SetIISRootPathParam=true then
      MessageBox(GetforegroundWindow,'修改成功!','提示信息',MB_OK)
     else
         MessageBox(GetforegroundWindow,'修改失败!','提示信息',MB_OK);
     if CreateIISVirtualPath('WebUser','E:\VC')=true then
      MessageBox(GetforegroundWindow,'建立成功!','提示信息',MB_OK)
     else
         MessageBox(GetforegroundWindow,'建立失败!','提示信息',MB_OK);
    end;procedure TForm1.Button4Click(Sender: TObject);
    begin
     if KillIISPath('WebUser')=true then
      MessageBox(GetforegroundWindow,'删除成功!','提示信息',MB_OK)
     else
         MessageBox(GetforegroundWindow,'删除失败!','提示信息',MB_OK);
    end;end.
      

  2.   

    ISAPI过滤器的开发需要完成三个接口DLL函数即可。它们是GetFilterVersion()、HttpFilterProc()、TerminateFilter(),大家可以查看MSDN了解详细的用法
      

  3.   

    isapi过滤器怎么加??
    就是像php那样,要加一个.php的,把php.exe那个加进去
      

  4.   

    为使ISAPI过滤器能够运行,您需要在注册表的HKEY_LOCAL_MACHINE\System\CurrentControlSet\
    Services\W3SVC\Parameters下建立一个字符串项,其名称为"Filter Dlls",值为ISAPI过滤器文件的全路径名称。若这个字符串项已经存在,只需把它的全路径名称加入其中,不同的ISAPI过滤器文件之间用";"分隔,您可以根据执行的优先顺序加在适当的位置。设置好后重新启动IIS服务,您的ISAPI过滤器就发挥作用了。 
      

  5.   

    不行?
    我说得是
    isapi过滤器怎么加??
    就是像php那样,要加一个.php的,把php.exe那个加进去,才能运行php的php这个是怎么实现的?
      

  6.   

    这个我做过,去年用CB5做过一个COM+组件,实现的功能就是配置IIS,可以建站点、虚拟目录、拷贝文件、设置权限、主目录、IP地址等等。实现的思路是通过调用微软的ADSI(活动目录服务接口),然后给定元路径,如'IIS://localhost/w3svc',就可以对相应的对象进行访问了。在PHP活ASP里面可以创建COM+组件里面的对象,然后得到相应的方法就可以实现相应的操作了。
      

  7.   

    转贴  大富翁论坛 第188072号帖子首先确认,API是绝对解决不了这些问题的,必须使用COM,使用ADSI接口。
    在WinNT\System32下的adsiis.tlb是MS封装的ADSI公开接口,非常的全,也非常之庞大。你可
    以使用它,也可以去这儿下载一个公开源码的ADSI COM控件。但是,它是C写的。
        ftp://ftp.15seconds.com/990107.zip
    打开990107.zip,用regsvr32.exe myadsi.dll注册这个控件。然后,你就可以开始用Delphi
    干活儿了。一、生成接口文件
    ------------------------------------------------------------------------
    由于myADSI.dll不是OCX/EXE方式的ActiveX服务,所以,必须手工生成TLB接口文件。
    运行\Delphi\BIN目录的TLIBImp.exe文件。如下:
      tlibimp -L+ MyADSI.dll
      // L+参数是生成能够在Delphi的IDE环境中使用的可视组件。可选。
      // 如果你使用adsiis.tlb,也需要用tlibimp来生成接口文件。
    这个控件的编写者有病,会将COM控件命名为Contorl,生成的Delphi类名叫TControl,与
    Delphi自己的一个控件会冲突,所以你需要打开生成的myADSILib_TLB.pas文件,将所有的
    TControl替换成TIISControl。就成了。——你也可以不替换,但出了问题可被怪我。 :)二、安装组件
    ------------------------------------------------------------------------
    安装myADSILib_TLB.pas到组件板,与普通操作无二。不讲了。三、编程
    ------------------------------------------------------------------------
    太简单了。 ^-^。下面假设控件名:IISConfig
    var selectDir : integer;     //示例中用来控制创建的虚拟目录类型。
    procedure TMainForm.Button1Click(Sender: TObject);
    const //Permissions Const, From MSDN.
      IISReadAccess     = 1;
      IISWriteAccess    = 2;
      IISExecuteAccess  = 4;     //(including ScriptAccess)
      IISScriptAccess   = 512;
    var
      VDirName : string;
    begin
      VDirName := Edit1.Text;
      if (VDirName='') or (VDirName[1]='/') then
        begin
          showMessage('虚拟目录不能为空, 且第一个字符不能为''/''.'#$0D'请重新填写.');
          exit;
        end;  IISConfig.Site := 1;  //如果IIS中有多个Web Site,这里可选。
      IISConfig.Connect;
      try
        if BOOL(IISConfig.ExistsVDir(VDirName))
          then showMessage('对不起, 该虚拟目录已经存在.'#$0D'不能创建虚拟目录.')
          else
            case selectDir of
              1 : //普通目录
                begin
                  IISConfig.Permissions := IISReadAccess;
                  if not BOOL(IISConfig.CreateVDir(WideString(PBF.Folder), WideString(VDirName))) then
                    showMessage('对不起, 未知情况导致虚拟目录不能成功创建.');
                end;
              2 : //脚本目录
                begin
                  IISConfig.Permissions := IISExecuteAccess;
                  if not BOOL(IISConfig.CreateVDir(WideString(PBF.Folder), WideString(VDirName))) then
                    showMessage('对不起, 未知情况导致虚拟目录不能成功创建.');
                end;
            end;
      finally
        IISConfig.Disconnect;
      end;
    end;就这样啦。不难的。
    TIISControl主要有三个功能:CreateVDir(), ExistsVDir(), DeleteVDir()。
    OnStartPage()和OnEndPage()两个功能我也没有太搞明白,好象是设置ASP的起始和结束页的。
    Permissions设置的全部定义是:
    {  //Define In MSDN
        MD_ACCESS_READ 0x00000001 Allow read access.
        MD_ACCESS_WRITE 0x00000002 Allow write access.
        MD_ACCESS_EXECUTE 0x00000004 Allow file execution (includes script permission).
        MD_ACCESS_SOURCE 0x00000010 Allow source access.
        MD_ACCESS_SCRIPT 0x00000200 Allow script execution.
        MD_ACCESS_NO_REMOTE_WRITE 0x00000400 Local write access only.
        MD_ACCESS_NO_REMOTE_READ 0x00001000 Local read access only.
        MD_ACCESS_NO_REMOTE_EXECUTE 0x00002000 Local execution only.
        MD_ACCESS_NO_REMOTE_SCRIPT 0x00004000 Local host access only. }
    但注意MyASDI中的Permissions是smallInt类型的。小有区别啦。 ^-^四、其它
    ------------------------------------------------------------------------
    如果你要发布软件的话,当然不能要用户自已去运行regsvr32.exe来注册MyADSI.dll了。
    如果你不是使用专门的安装工具来做这件事的话,你可以用一段小程序来完成这件事。
    type
      TRegisterMode = (regRegister, regUnregister);
    function OLERegisterDLLFile (strFileName : STRING; mode : TRegisterMode) : BOOLEAN;
    type
      TOleRegister = function : HResult;
    var
      hLib : THandle;
      fnAdr: TFarProc;
    begin
      Result := FALSE;
      hLib := LoadLibrary(PCHAR(strFileName));
      if (hLib > 0) then
      begin
        try
          if (mode = regRegister) then
            fnAdr := GetProcAddress(hLib, pchar('DllRegisterServer'))
          else
            fnAdr := GetProcAddress(hLib, pchar('DllUnregisterServer'));
          if (fnAdr <> nil) then
            Result := (TOleRegister(fnAdr) >= 0);
        finally
          FreeLibrary(hLib);
        end;
      end;
    end; { RegisterDLLFile }OLERegisterDLLFile()函数可以加到TForm.onCreate和TForm.onClose事件中。即可以完成
    自动注册和卸载。
    好了。用Delphi简单吧?^-^五、关于ASP
    ------------------------------------------------------------------------
    需要的话,去查MSDN,关键字:“Virtual directories, creating”。也可以去MS的MSDN网
    站,查“Create a Virtual Directory Automatically with ADSI”,就成了。
    不会要我将这个也贴上来吧?哈哈哈。