【问题标题】:How do I create an IIS application and application pool using Inno Setup script如何使用 Inno Setup 脚本创建 IIS 应用程序和应用程序池
【发布时间】:2010-08-18 13:52:19
【问题描述】:

我正在尝试使用 Inno Setup 部署 ASP.NET 应用程序。

我需要执行以下任务:

  1. 创建一个 IIS 应用程序。
  2. 创建一个新的 IIS 应用程序池并将其 .NET 版本设置为 4。
  3. 将新应用的应用池设置为新应用池。

我找到了一个创建虚拟目录的脚本,但是我需要一个应用程序和应用程序池:

procedure CreateIISVirtualDir();
var
  IIS, WebSite, WebServer, WebRoot, VDir: Variant;
  ErrorCode: Integer;
begin
  { Create the main IIS COM Automation object }

  try
    IIS := CreateOleObject('IISNamespace');
  except
    RaiseException(
      'Please install Microsoft IIS first.'#13#13'(Error ''' +
      GetExceptionMessage + ''' occurred)');
  end;

  { Connect to the IIS server }

  WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
  WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
  WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');

  { (Re)create a virtual dir }

  try
    WebRoot.Delete('IIsWebVirtualDir', 'eipwebv4');
    WebRoot.SetInfo();
  except
  end;

  VDir := WebRoot.Create('IIsWebVirtualDir', 'eipwebv4');
  VDir.AccessRead := True;
  VDir.AccessScript := TRUE;
  VDir.AppFriendlyName := 'Easy-IP Web Client';
  VDir.Path := ExpandConstant('{app}');
  try
    VDir.AppPoolId := 'Classic .NET AppPool';
  except
  end;

  VDir.AppCreate(True);
  VDir.SetInfo();
end;

【问题讨论】:

    标签: asp.net iis inno-setup


    【解决方案1】:

    这个问题是很久以前提出的,但也许有人会发现这个用于 IIS6/IIS7 的脚本很有用:

    var
      global_AppCmdFilePath :String;
      global_IsIIS7 :Boolean;
      global_WebSites :SiteList;
      global_WebSiteName :String;
      global_vDir :String;
      global_AppCmdExitCode :Integer;
    
    const
      IISServerName = 'localhost';
      IISApplicationPoolName = 'Test Pool';
    
      ERROR_NOT_FOUND = 1168;
      ERROR_NOT_SUPPORTED = 50;
    
      MD_APPPOOL_IDENTITY_TYPE_LOCALSYSTEM = 0;
      MD_APPPOOL_IDENTITY_TYPE_LOCALSERVICE = 1;
      MD_APPPOOL_IDENTITY_TYPE_NETWORKSERVICE = 2;
      MD_APPPOOL_IDENTITY_TYPE_SPECIFICUSER = 3;
    
      MD_LOGON_INTERACTIVE = 0;
      MD_LOGON_BATCH = 1;
      MD_LOGON_NETWORK = 2;
      MD_LOGON_NETWORK_CLEARTEXT = 3;
    
    function ExecAppCmd(params :String) :Boolean;
    var
      execSuccessfully :Boolean;
      resultCode :Integer;
    begin
      execSuccessfully := Exec('cmd.exe', '/c ' + global_AppCmdFilePath + ' ' + params, '', SW_HIDE, ewWaitUntilTerminated, resultCode);
    
      global_AppCmdExitCode := resultCode;
    
      Result := execSuccessfully and (resultCode = 0);
    end;
    
    
    function CreateVirtualDirectoryForIIS6(physicalPath :String) :String;
    var
      IIS, webService, webServer, webRoot, vDir, vDirApp :Variant;
      appPools, appPool :Variant;
      webSiteId :String;
    begin
      webSiteId := GetWebSiteIdByName(global_WebSiteName);
    
      { Create the main IIS COM Automation object. }
      IIS := CreateOleObject('IISNamespace');
    
      { Get application pools. }
      appPools := IIS.GetObject('IIsApplicationPools', 'localhost/W3SVC/AppPools');
    
      try
        { Check if the application pool already exists. }
        appPool := appPools.GetObject('IIsApplicationPool', IISApplicationPoolName);
      except
        { Crete the application pool. }
        try
          appPool := appPools.Create('IIsApplicationPool', IISApplicationPoolName);
    
          appPool.LogonMethod := MD_LOGON_NETWORK_CLEARTEXT;
          appPool.AppPoolIdentityType := MD_APPPOOL_IDENTITY_TYPE_NETWORKSERVICE;
    
          appPool.SetInfo();
        except
          Result := 'Failed to create an apllication pool.';
          Exit;
        end;
      end;
    
      { Connect to the IIS server. }
      webService := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
    
      { Get the website. }
      webServer := webService.GetObject('IIsWebServer', webSiteId);
      webRoot := webServer.GetObject('IIsWebVirtualDir', 'Root');
    
      { Delete the virtual dir if it already exists. }
      try
        webRoot.Delete('IIsWebVirtualDir', global_vDir);
        webRoot.SetInfo();
      except
        { An exception will be raised if there is not such a website. }
      end;
    
      { Create the virtual directory. }
      try
        vDir := WebRoot.Create('IIsWebVirtualDir', global_vDir);
    
        vDir.AccessRead := True;
        vDir.AccessScript := True;
        vDir.AppFriendlyName := 'Test friendly name';
        vDir.Path := physicalPath;
    
        vDir.AppCreate(False);
    
        vDir.SetInfo();
      except
        Result := 'Failed to create a virtual directory.';
        Exit;
      end;
    
      { Assign the application pool to the virtual directory. }
      try
        vDir := webRoot.GetObject('IIsWebVirtualDir', global_vDir);
    
        vDir.AppPoolId := IISApplicationPoolName;
    
        vDir.SetInfo();
      except
        Result := 'Failed to assign the application pool to the virtual directory.';
        Exit;
      end;
    end;
    
    function CreateVirtualDirectoryForIIS7(physicalPath :String) :String;
    var
      tempFileName :String;
      appPoolList :String;
      createAppPool :Boolean;
    begin
      { Delete the application if it already exists. }
      if not ExecAppCmd(Format('delete app "%s/%s"', [global_WebSiteName, global_vDir])) then
      begin
        if (global_AppCmdExitCode <> ERROR_NOT_FOUND) and (global_AppCmdExitCode <> ERROR_NOT_SUPPORTED) then
        begin
          Result := 'Failed to delete the application.  ' + GetErrorMessageByCode(global_AppCmdExitCode);
          Exit;
        end;
      end;
    
      { Check if the application pool already exists. }
      tempFileName := ExpandConstant('{tmp}\AppPoolNames.txt');
    
      ExecAppCmd(Format('list apppool "%s" > "%s"', [IISApplicationPoolName, tempFileName]));
    
      if (LoadStringFromFile(tempFileName, appPoolList)) then
      begin
        createAppPool := (Pos(IISApplicationPoolName, appPoolList) = 0);
      end
      else
      begin
        createAppPool := True;
      end;
    
      { Create the application pool. }
      if (createAppPool) then
      begin
        if not ExecAppCmd(Format('add apppool /name:"%s" /managedRuntimeVersion:v4.0', [IISApplicationPoolName])) then
        begin
          Result := 'Failed to add the application pool. ' + GetErrorMessageByCode(global_AppCmdExitCode);
          Exit;
        end;
      end;
    
      { Create the application. }
      if not ExecAppCmd(Format('add app /site.name:"%s" /path:"/%s" /physicalPath:"%s" /applicationPool:"%s"', [global_WebSiteName, global_vDir, physicalPath, IISApplicationPoolName])) then
      begin
        Result := 'Failed to add the application. ' + GetErrorMessageByCode(global_AppCmdExitCode);
        Exit;
      end;
    
      Result := '';
    end;
    

    【讨论】:

    • 首先感谢您的回复,这正是我需要做的,但我很难弄清楚。首先,例如,在尝试 createVirtualDirectoryForIIs7 时,我需要发送什么作为“物理路径”?
    • 'physicalPath' 是磁盘上存储 ASP.NET 应用程序的路径。
    • 这是否意味着我需要在脚本的 [Files] 块中包含与 ASP.NET 应用程序有关的所有文件?再次感谢您帮助我
    • 是的。您应该在 [Files] 部分中包含所有 APS.NET 应用程序文件。否则你将如何将它们交付给客户机器?
    • 是的,你说得对。但是要记住一件事。如果您在 [Code] 部分使用 {localappdata} 或 {app} 等常量,则应使用 ExpandConstant 方法(如 ExpandConstant('{app}'))。顺便说一句,我不确定在本地(非漫游)应用程序数据文件夹中安装站点是否是个好主意。
    【解决方案2】:

    你去:http://learn.iis.net/page.aspx/285/provisioning-sample-in-c/

    向下滚动Create Application Pool。它将向您展示如何创建 AppPool、Application 和 VirtualDirectories。

    【讨论】:

    • 谢谢,但我正在寻找使用 Innosetup 的示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多