How do I create an IIS application and application pool using InnoSetup script

  • Create an IIS application.
  • Create a new IIS application pool and set it's .NET version to 4.
  • Set the application pool of the new application to the new application pool.
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;

 

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;

 

 

时间: 2024-10-03 14:52:48

How do I create an IIS application and application pool using InnoSetup script的相关文章

IIS 错误 Server Application Error 详细解决方法_ASP基础

Server Application ErrorThe server has encountered an error while loading an application during the processing of your request.Please refer to the event log for more detail information.Please contact the server administrator for assistance. 方法 1:在用户管

iis出现Server Application Error 解决办法

server application error the server has encountered an error while loading an application during the processing of your request. please refer to the event log for more detail information. please contact the server administrator for assistance. 访问iis客

IIS提示Server Application Error的解决方法集锦第1/2页_win服务器

Server Application Error The server has encountered an error while loading an application during the processing of your request. Please refer to the event log for more detail information. Please contact the server administrator for assistance. 访问IIS客

解决IIS的Server Application Error的2种方法_服务器

方法1:  ------------------------------------   Server Application Error   The server has encountered an error while loading an application during the processing of your request. Please refer to the event log for more detail information. Please contact 

IIS 错误 Server Application Error 详细解决方法

Server Application Error The server has encountered an error while loading an application during the processing of your request.Please refer to the event log for more detail information.Please contact the server administrator for assistance. 方法 1:在用户

What&amp;#39;s New in the Web Server (IIS) Role (IIS 7)

What's New in the Web Server (IIS) Role (IIS 7) What are the major changes? Many features have been added or enhanced in Internet Information Services (IIS) 7.5, which is the foundation of the Web Server role in Windows Server 2008 R2. The following

IIS各个版本中你需要知道的那些事儿

一.写在 前面 &http://www.aliyun.com/zixun/aggregation/37954.html">nbsp;   目前市面上所用的IIS版本估计都是>=6.0的.所以我们主要以下面三个版本进行讲解 服务器版本 IIS默认版本server20036.0server20087.0server20128.0 二.IIS6的请求过程 由图可知,所有的请求会被服务器中的http.sys组件监听到,它会根据IIS中的 Metabase 查看基于该 Request

艾伟:用 IIS 7、ARR 與 Velocity 建置高性能的大型网站

本帖是研讨会中的一些杂记,搭配一些官方的文档,经整合归纳后,介绍 IIS 7 如何搭配新一代的 ARR (Application Request Routing),建置 Server Farm 并达到比过去 NLB 更优的 Load Balancing 功能,此外还介绍微软新一代的分布式缓存技术 Velocity. -------------------------------------------------------------------------------------------

解析ASP的Application和Session对象

application|session|对象 在已经发表的系列文章中我们已经讨论了两个ASP对象:Application对象和Session对象,因此能够访问Application对象和Session对象提供的集合.方法.属性和事件.本节将从程序设计的角度对这两个对象进行研究. · 当载入ASP DLL并响应对一个ASP网页的第一个请求时,创建Application对象.该对象提供一个存储场所,用来存储对于所有访问者打开的所有网页都可用的变量和对象. · 当访问者首次从站点请求一个ASP页面时,