July 10, 2012

Restarting IIS in MSI using VBScript Custom Action

This article focus on writing a Simple VBScript Custom Action to Restart IIS.

1. Create a VBScript Custom Action (RestartIIS) Stored in Binary Table (MSI Type Number: 6)

2. Write the following code in the VBScript file
Function RestartIIS()
     Set wsShell = CreateObject("WScript.Shell")
     Set fso = CreateObject("Scripting.FileSystemObject")

     winPath = WsShell.ExpandEnvironmentStrings( "%windir%" )
     netPath = fso.BuildPath( winPath, "system32" )
     toolPath = fso.BuildPath( netPath, "iisreset.exe" )
     WsShell.Run toolPath, 0, true
     set fso=nothing
     set WsShell=nothing  
End Function
3. Set the following properties for the Custom Action (RestartIIS) 
    Script Function -> RestartIIS
    Return Processing -> Synchronous (Check exit code)
    In-Script Execution -> Immediate Execution
    Install Exec Sequence -> After InstallFinalize
    Install Exec Condition -> &FeatureA=3 and Installed
                                           This condition means that FeatureA is selected for installation and the FeatureA is installed (Installed state will be true as the CA is scheduled to execute after InstallFinalize).
[Note: This code snippet is tested with InstallShield 2012 Basic MSI Project. Should be compatible with earlier versions of InstallShield as well.]

No comments:

Post a Comment