Populate a combobox using a custom action

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • feiock
    Forum Member
    • Jan 2008
    • 18

    Populate a combobox using a custom action

    Hello,
    Is there a sample anywhere that shows how to populate a combobox using a custom action...preferably a VBScript? I have looked all over and can't seem to find anything on that subject.

    What I am trying to do is query IIS for a list of the WebSites currently on the machine and populate them in a combobox for the user to select. From what I have gathered so far, in order to do this, I would need a script like this (found from a WiX tutorial site):

    Const ERROR_SUCCESS = 0
    Const ERROR_INSTALL_FAILURE = 1603
    Const msiViewModifyInsertTemporary = 7

    Function GetSites()
    Dim objIIS, oView, oSite, oServer, oReccombo
    Dim r

    On Error Resume Next
    Set objIIS = GetObject("IIS://localhost/W3SVC")
    If Err.Number <> 0 Then
    MsgBox "Unable to open IIS W3SVC Root object - " & _
    "please ensure that IIS is running" & vbCrLf & _
    " - Error Details: " & Err.Description & " [Number:" & _
    Hex(Err.Number) & "]", vbCritical, "Error"
    GetSites = ERROR_INSTALL_FAILURE
    Exit Function
    Else
    ' open and execute a view to the ListBox table
    Set oView = Session.Database.OpenView("SELECT * FROM `ComboBox`")
    oView.Execute
    r = 0
    For Each oSite in objIIS
    r = r + 1
    If oSite.Class = "IIsWebServer" Then
    Set oServer=GetObject(oSite.ADsPath)
    ' ComboBox record fields are Property, Order, Value, Text
    Set oReccombo = Session.Installer.CreateRecord(4)
    oReccombo.StringData(1) = "CLIENTSITE"
    oReccombo.IntegerData(2) = r
    oReccombo.StringData(3) = oSite.Name
    oReccombo.StringData(4) = oServer.Get("ServerComment")
    oView.Modify msiViewModifyInsertTemporary, oReccombo

    Set oReccombo = Session.Installer.CreateRecord(4)
    oReccombo.StringData(1) = "ADMINSITE"
    oReccombo.IntegerData(2) = r
    oReccombo.StringData(3) = oSite.Name
    oReccombo.StringData(4) = oServer.Get("ServerComment")
    oView.Modify msiViewModifyInsertTemporary, oReccombo
    wscript.echo oServer.Get("ServerComment")
    End If
    Next
    oView.Close
    ' return success to MSI
    GetSites = ERROR_SUCCESS
    End If

    ' clean up
    Set objIIS = Nothing
    Set oView = Nothing
    End Function

    This would populate the record ADMINSITE with the list of available websites. This functionality appears to be working ok. What I can't figure out is how to wire this to SUF. If I go into the dialog editor, and then to edit the .xml, I have tried many different variations of this:

    <Control Id="AdmSiteCombo" Type="ComboBox" X="14" Y="31" Width="200" Height="17" Property="ADMINSITE" Text="Test" ComboList="yes" >
    <ComboBox Property="ADMINSITE">
    <ListItem Value="Test"/>
    </ComboBox>

    I have tried with and without list values, I have tried setting the property up ahead of time, not having the property at all, etc. No matter what I do, the combobox will show up empty, or not with the values that are being returned from my script.

    However, I have discovered on important thing (may be a bug?) is that you need to add a "dummy" combobox somewhere in your UI so that the ComboBox table is created in the .msi. If this does not happen, then the SELECT statement above will fail.

    Any ideas or examples would be greatly appreciated.
  • feiock
    Forum Member
    • Jan 2008
    • 18

    #2
    I figured out what was missing. The custom action I had setup to run the VBScript to populate ADMINSITE was getting run later. So when it got to the screen to populate the combobox, ADMINSITE was empty, which is why it wasn't working. For anyone who is curious, here is the remainder of what I had to setup to get it working:

    Combobox control:

    <Control Id="AdmSiteCombo" Property="ADMINSITE" Type="ComboBox" X="6" Y="21" Width="208" Height="20" Text="Ppphhh" ComboList="yes" ToolTip="The website you would like to install to">
    <ComboBox Property="ADMINSITE"/>
    </Control>
    <Control Id="Control_Dummy" Property="DUMMY" Type="ComboBox" X="218" Y="4" Width="51" Height="17" Text="Poo" Hidden="yes" Disabled="yes">
    <ComboBox Property="DUMMY">
    <ListItem Value="filler"/>
    </ComboBox>
    </Control>

    Notice, I had to create a "Control_Dummy" combobox so the ComboBox table is created in the .msi. If you populate your combobox by CA only, you have to do this.

    CustomAction:

    <CustomAction Id="GetIISSites" Impersonate="yes" Return="check" Execute="immediate" BinaryKey="InstallationFunctions.vbs" VBScriptCall="GetSites"/>
    <Binary Id="InstallationFunctions.vbs" SourceFile="C:\temp\InstallationFunctions.vbs"/>
    <InstallUISequence>
    <Custom Action="GetIISSites" Before="InstallDirDlg">1</Custom>
    </InstallUISequence>


    Along with the script above, that should be it.

    Comment

    Working...
    X