How can InstallBuilder be used to create IIS application pools and virtual directories?

Answered

Comments

1 comment

  • Avatar
    wojciechka

    InstallBuilder does not provide built-in actions for this purpose, however, it is easy to do this using <runProgram> action.

    For Microsoft Internet Information Services 7, the appcmd.exe binary that is deployed as part of IIS can be used. The following is an example of creating an application pool and virtual directory for IIS 7:

    <postInstallationActionList>
      <setInstallerVariable>
        <name>appcmd</name>
        <value>${env(SystemRoot)}\\system32\\inetsrv\\appcmd.exe</value>
      </setInstallerVariable>
      <writeFile>
        <path>${installdir}/configure_iis.bat</path>
        <text>@echo off
    "${appcmd}" add apppool /name:"${iis_site_name}"
    "${appcmd}" add vdir /app.name:"${iis_site_name}/" /path:/${iis_virtualdir_name} /physicalPath:"${iis_virtualdir}"
    </text>
      </writeFile>
      <runProgram>
        <program>${installdir}/configure_iis.bat</program>
        <programArguments></programArguments>
      </runProgram>
      <deleteFile>
        <path>${installdir}/configure_iis.bat</path>
      </deleteFile>
    </postInstallationActionList>
    

    The script creates an application pool and virtual directory, where:

    ${appcmd} refers to the appcmd.exe path that is set in first action. ${iis_site_name} could be 'Default Web Site' or any other web site. ${iis_virtualdir_name} would be the virtual directory ${iis_virtualdir} would be the physical path.

    Additional information about appcmd.exe can be found in the following Microsoft documentation:

    Create a Virtual Directory (IIS 7)

    Appcmd.exe documentation

    Microsoft Internet Information Services 6 does not provide equivalent of appcmd.exe binary. However, it is possible to interact with it using VBS scripts. For example the script below deletes a virtual directory in IIS 6:

      <writeFile path="${installdir}\\${iis_virtualdir_script}">
        <text>On Error Resume Next
    Set IISObject = GetObject("IIS://LocalHost/W3SVC/1/ROOT/${iis_virtualdir_name}")
    IISObject.AppDelete
    If (Err.Number &lt;> 0) Then
      WScript.Quit (Err.Number)
    End If
    
    Set IISObject = GetObject("IIS://LocalHost/W3SVC/1/ROOT")
    IIsObject.Delete "IIsWebVirtualDir", "${iis_virtualdir_name}"
    If (Err.Number &lt;> 0) Then
      Wscript.Quit (Err.Number)
    End If
    
    </text>
      </writeFile>
      <runProgram>
        <program>cscript</program>
        <programArguments>"${installdir}/${iis_virtualdir_script}"</programArguments>
        <showMessageOnError>0</showMessageOnError>
        <abortOnError>0</abortOnError>
      </runProgram>
    

    Additional information about automating IIS 6 can be found below:

    HOWTO: Create Custom Application Pool from Commandline

    Using the Adsutil.vbs Administration Script (IIS 6.0)

Please sign in to leave a comment.