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-26 03:36:16

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

关于Application.Lock…Application.Unlock有什么作用?

因为Application变量里一般存储的是供所有连接到服务器的用户共享的信息(就像程序中所说的 "全局变量 "), 由于是全局变量,所以就容易出现两个或者多个用户同时对这一变量进行操作的情况从而产生冲突,而Application.Lock和Application.Unlock就是为了解决这一问题的, 使用Lock就能确保了在某一时段所有连接到服务器的用户之中只有一个用户能获得存取或修改该Application变量的权限(即对该公共变量进行锁定操作).其它任何用户想要获得这样的权限就必

c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.ExitThread(); System.Environment.Exit(0);

本文实例总结了C#中WinForm程序退出方法技巧.分享给大家供大家参考.具体分析如下: 在c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.ExitThread(); System.Environment.Exit(0); 等他们各自的方法不一样,下面我们就来详细介绍一下. 1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退

spring boot中的底层配置文件application.yam(application.property)的装配原理初探

*在spring boot中有一个基础的配置文件application.yam(application.property)用于对spring boot的默认设置做一些改动. *在spring boot中有集成很多其他的包或者框架,如redis的操作的包,日志的等等. *在spring boot程序启动的时候,也就是下面这个类: @SpringBootApplicationpublic class Springboot1Application { public static void main(S

解决pip install package时Fatal error in launcher: Unable to create process using &#39;&quot;e:\python36\python3.exe&quot; &quot;E:\python36\Script\pip3.exe&quot;问题

pip 运行报错: 关于:Fatal error in launcher: Unable to create process using '"e:\python36\python3.exe"  "E:\python36\Script\pip3.exe"问题 由于安装tensorflow,下载 了Anaconda2环境,自此python有了2.7 和3.6两个版本,同时在tensorflow虚拟环境中安装了python3.5版本用来运行tensorflow. 今天本想

IIS 7.5 Application Warm-Up Module

http://www.cnblogs.com/shanyou/archive/2010/12/21/1913199.html 有些web应用在可以处理用户访问之前,需要装载很多的数据,或做一些花费很大的初始化处理.今天使用 ASP.NET 的开发人员经常使用应用的Global.asax  文件中的 “Application_Start”事件处理函数来做这些工作(该事件是在第一个请求执行时触发的).他们要么设计定制脚本,周期性地向应用发假的请求,来“唤醒它(wake it up)”,从而在客户访问

Create a Qt Widget Based Application—Windows

This turtorial describes how to use Qt Creator to create a small Qt application, Text Finder. It is a simplified version of the Qt UI Tools Text Finder Example. The application user interface is constructed from Qt widgets by using Qt Designer. The a

修改本机iis中所有application pool的identity(OfficeServerApplicationPool除外) c#

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.DirectoryServices; using System.Collections; namespace ResetIISApplicationIdentity {     class Program     {         static void Main(string[] args)   

Manage and Create Journals in Oralce Fusion Application

Open slcai806 environment with FINUSER1/*********, we will see the welcome page. Click 'Navigator' button and select 'General Accounting Dashboard' which is under General Accounting, we will go to General Accounting page. In this page, we can do some

Application.streamingAssetsPath Application.persistentDataPath

出处:https://www.jianshu.com/p/9b4bab5ecbc2 Application.streamingAssetsPath 在ios端和Android端 只能读取而不能修改, 一般在这个文件夹里面存放一些二进制文件(比如AssetBundle,mp4等一些文件), 这些文件在打包时不会被压缩(最好只放少量的文件,而且要做好加密工作,不然别人一解压就得到了里面的内容了),因此读取的速度是比较快的. 在Android端读取这个文件夹时,只能使用WWW进行异步读取,而在ios和