\
Tips and Tricks
User Interface Tips
Dynamically Update Dialog Controls
Dynamically Update Dialog Controls |
The source of this tip is "TryMeWithUserDialog.MM" so
please see it for a complete example.
This code demonstrates the basics of dynamically making in memory updates
to an MSI while it is executing.
You would do this as you are examining the
environment and possibly providing relevant choices to a user.
This code assumes there is a "ComboBox" control called "ANSWER6" and
notice that the custom action is of type "immediate"
(a deferred CA can't update the database!).
Similar code could of course make any other database changes (to any tables)
you might need to make.
;----------------------------------------------------------------------------
;--- Dynamically insert records into a "ComboBox" dialog control ------------
;----------------------------------------------------------------------------
<$VbsCa Binary="AddEntriesToDialogControls.VBS">
;--- Initialization ------------------------------------------------------
const MSIMODIFY_INSERT_TEMPORARY = 7
dim oInstaller, oDB, oView 'Some globals
dim ErrNumb, ErrDesc
#define SAVE.ERR.DETAILS ErrNumb = err.number : ErrDesc = err.description
#define ADD.ERR.DETAILS vbCRLF & vbCRLF & "Reason 0x" & hex(ErrNumb) & " - " & ErrDesc
;--- INSTALL -------------------------------------------------------------
<$VbsCaEntry "UpdateControls">
;--- Extra a binary --------------------------------------------------
AddEntriesToDialogControls()
<$/VbsCaEntry>
<?NewLine><?NewLine>
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sub AddEntriesToDialogControls()
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;--- We will handle all errors ourselves -----------------------------
on error resume next
CaDebug 1, "Updating Dialog Controls as a demo..."
;--- Open the database -----------------------------------------------
CaDebug 0, "Opening the database"
set oInstaller = session.Installer
set oDB = session.Database
if err.number <> 0 then
<$SAVE.ERR.DETAILS>
on error goto 0
VbsCaRaiseError "AddEntriesToDialogControls()", "Tried to open the database..." & <$ADD.ERR.DETAILS>
end if
;--- Look for the BINARY ---------------------------------------------
CaDebug 2, "Opening a view to the ComboBox table"
set oView = oDB.OpenView("SELECT * FROM `ComboBox`")
oView.Execute()
if err.number <> 0 then
<$SAVE.ERR.DETAILS>
on error goto 0
VbsCaRaiseError "AddEntriesToDialogControls()", "Could not open a view to the ComboBox table..." & <$ADD.ERR.DETAILS>
end if
;--- Add lines (normally in some sort of loop looking at environment) ---
on error goto 0
AddComboBoxLine4ANSWER6 30000, "Fish (dynamic)", "Splash"
AddComboBoxLine4ANSWER6 30001, "Bird (dynamic)", "Tweet Tweet"
;--- Finish up -------------------------------------------------------
on error resume next
set oView = Nothing
set oInstaller = Nothing
set oDB = Nothing
end sub
<?NewLine><?NewLine>
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sub AddComboBoxLine4ANSWER6(Order, Text, Value)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;--- Create a blank record -------------------------------------------
on error resume next
CaDebug 0, "Adding control with value: " & Value
CaDebug 0, "Creating record..."
dim oRec : set oRec = oInstaller.CreateRecord(4)
if err.number <> 0 then
<$SAVE.ERR.DETAILS>
on error goto 0
VbsCaRaiseError "AddComboBoxLine4ANSWER6", "Failed adding blank record" & <$ADD.ERR.DETAILS>
end if
;--- Update the record we just created -------------------------------
CaDebug 0, "Updating Record..."
dim Property : Property = "ANSWER6"
oRec.StringData(1) = Property
oRec.IntegerData(2) = Order
oRec.StringData(3) = Value
oRec.StringData(4) = Text
if err.number <> 0 then
<$SAVE.ERR.DETAILS>
on error goto 0
VbsCaRaiseError "AddComboBoxLine4ANSWER6", "Failed updating the record (is Order=" & Order & " valid?)" & <$ADD.ERR.DETAILS>
end if
;--- Insert the record -----------------------------------------------
CaDebug 0, "Inserting into the view..."
oView.Modify MSIMODIFY_INSERT_TEMPORARY, oRec
if err.number <> 0 then
<$SAVE.ERR.DETAILS>
on error goto 0
VbsCaRaiseError "AddComboBoxLine4ANSWER6", "The record insertion failed" & <$ADD.ERR.DETAILS>
end if
end sub
<$/VbsCa>
<$VbsCaSetup Binary="AddEntriesToDialogControls.VBS" Entry="UpdateControls" Seq="<-WelcomeDlg" SeqTable="InstallUISequence" Type="Immediate" CONDITION=^<$CONDITION_INSTALL_ONLY>^>