Tuesday, November 12, 2013

Browse IIS Dialog in InstallShield

If you are familiar with InstallShield, you may already know that, by default, any version of InstallShield (including InstallShield 2013) does not ship with an out-of-the-box Browse IIS Dialog to be used as part of your installations.

I found this article on how to create a VBScript that can help with populating your IIS Websites to be used in creating your Browse IIS Dialog:  http://ruskin-dantra.blogspot.com/2009/10/using-vb-to-show-iis-sites-within.html

However, this article has 2 major flaws:

  1. The VBScript does not properly work when created as a Custom Action within InstallShield (numerous VBScript errors result)
  2. The VBScript only supports IIS 6.


Therefore, if you desire a VBScript Custom Action that supports IIS 7 and above, you are out of luck and are left to create your own.

Fortunately, I had the need to create such a Custom Action myself and therefore I am providing it for you here:

'Call the function to populate the dropdown list with the appropriate
'website names
PopulateWebsites "IISWEBSITE"

'This function populates the dropdownlist using the specified property name
'passed in as a parameter to the function
Function PopulateWebsites(sPropertyName)

Dim objView
Dim objDB
Dim objInstaller
Dim objRecord
Dim objW3SVC, objIisWebSite
Dim lngOrder
Set objDB = Session.Database
Set objInstaller = Session.Installer

'Delete any records that may exist
Set viewList = objDB.OpenView("SELECT * FROM ComboBox")
viewList.Execute

Set recList = viewList.Fetch

'delete any existing records
While Not (recList Is Nothing)
viewList.Modify 6, recList ' 6 = deleteSet
recList = viewList.Fetch
Wend

viewList.Close

Set objView = objDB.OpenView("select * from ComboBox")

' enumerate webservers on localhost and populate ComboBox tableSet
Dim oWebSites

' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

'Obtain instances of the Web Sites on the server
Set oWebSites = oWebAdmin.InstancesOf("Site")

lngOrder = 1

For Each objIisWebSite In oWebSites
' add site name to ComboBox table (which is used by our dialog ComboBox)
Set objRecord = objInstaller.CreateRecord(4)
objRecord.StringData(1) = sPropertyName ' property name
objRecord.IntegerData(2) = lngOrder ' order
objRecord.IntegerData(3) = objIisWebSite.Id ' value
objRecord.StringData(4) = objIisWebSite.Name ' text
objView.Execute objRecord ' now add the record to the table
objView.Modify 7, objRecord ' (7 = msiViewModifyInsertTemporary)
lngOrder = lngOrder + 1
Next

Call objView.Close

'Clean up
Set oWebSites = Nothing
Set oWebAdmin = Nothing

End Function

Well, once you have the script, what do you need to do next?  Well, below are the steps for creating your very own Browse IIS Dialog:

  1. Add a VBScript Custom Action to the "Custom Actions and Sequences" section in InstallShield Designer.
  2. Add theVBScript Custom Action to the User Interface sequence so that it occurs sometime before the Browse IIS Dialog will display.
  3. Create a property in "Property Manager" that will house the value for your Combobox in the Browse IIS Dialog (I used IISWEBSITE in my VBScript)
  4. In the "Dialogs" section, create a new Dialog with a Combobox control.  Attach the property that you just created in "Property Manager" to the Combobox.
  5. Alter any additional properties that you might need to alter in your Dialog such as the Title, Description etc.
  6. In the Behavior for the Dialog, make sure that your Event sequencing for your Back and Next buttons are correct so that the Browse IIS Dialog appears in the right sequence as part of your User Interface.
  7. Test your User Interface and verify that the Browse IIS Dialog appears and correctly renders the listings of your IIS Websites!

No comments:

Post a Comment