Start Program at End of Install |
The following is a complete MSI script which will automatically invoke a program (either installed by your MSI or a pre-existing file):
;--- Load MAKEMSI (via my personal branding and configuration file) -------- #include "ME.MMH" ;--- Define installation directory and install file to this location -------- <$DirectoryTree Key="INSTALLDIR" Dir="[ProgramFilesFolder]\MyTestDir" CHANGE="\" PrimaryFolder="Y"> <$Component "Simple" Directory_="INSTALLDIR"> <$File Source="D:\DBAREIS\tools\MsgBox.exe" RowKey="MsgBox.EXE" KeyPath="Y"> <$/Component> ;--- Invoke the install executable ------------------------------------------ #( ;--- Run after install, ignore return code and don't wait for completion --- <$ExeCa EXE="[INSTALLDIR]MsgBox.exe" Args=^"MsgBox Title" "MsgBox text..."^ ;EXE="[SystemFolder]notepad.exe" Args="c:\tmp\1.x" WorkDir="INSTALLDIR" SEQ="InstallFinalize-" Type="immediate ASync AnyRc" Condition="<$CONDITION_INSTALL_ONLY>" > #)
You may wish to invoke the program from the last dialog as shown here:
If so the following code invokes a macro (defined further below):
<$LaunchProductCheckBox EXE="[INSTALLDIR]MsgBox.exe" Args=^"MsgBox Title" "MsgBox text..."^>
The macro used by the above code follows:
#( #define LaunchProductCheckBox ;--- Validate passed parameters ----------------------------------------- {$!:EXE,ARGS,WORKDIR,TEXT} ;--- Add a checkbox to the final dialog --------------------------------- <$Property "LAUNCHPRODUCT" Value="1"> ;;Default is ticked. <$Table "Control"> #( <$Row Dialog_="ExitDialog" Control="LaunchProductCheckBox" Type="CheckBox" Property="LAUNCHPRODUCT" X="10" Y="243" Width="150" Height="17" Attributes="&H10003" Text=^{$Text="Launch [ProductName]"}^ Control_Next="" Help="" > #) <$/Table> ;--- We don't always want to see the checkbox --------------------------- <$Table "ControlCondition"> #( ;--- Hide the checkbox if package already installed ----------------- <$Row Dialog_="ExitDialog" Control_="LaunchProductCheckBox" Action="Hide" Condition="Installed" > #) <$/Table> ;--- What value is put in property if checkbox is ticked? --------------- <$Table "CheckBox"> <$Row Property="LAUNCHPRODUCT" Value="1"> <$/Table> ;--- Call our custom action ("ExeCa" below) when "Finish" button pressed --- <$Table "ControlEvent"> #( <$Row Dialog_="ExitDialog" Control_="Finish" Event="DoAction" Argument="CaLaunchProductCheckBox" Condition="(NOT Installed) AND (LAUNCHPRODUCT = 1)" Ordering="" > #) <$/Table> ;--- Custom Action (not scheduled but runs via dialog) ------------------ #( <$ExeCa Key="CaLaunchProductCheckBox" EXE="{$EXE}" Args=^{$Args}^ ;EXE="[SystemFolder]notepad.exe" Args="c:\tmp\1.x" WorkDir="{$WorkDir=''}" Seq="0" SeqTable="" Type="immediate ASync AnyRc" Condition="<$CONDITION_INSTALL_ONLY> and LAUNCHPRODUCT=1" > #) #)
The macro above modifies the "ExitDialog" and is based on code written by Julian Onions. Thanks again Julian!
Of course nothing stops you creating your own dialog containing a checkbox like the above.
If the "program" is a batch file the you should have a look at the "Batch File Custom Actions" section.
Grey Background on Controls! |
I've put the checkbox on the gray part of the dialog as its is not possible for checkbox (or other) controls to site nicely on a non-default (generally gray) background as the "transparent" attribute doesn't work.
If you tried putting the checkbox on the white part it just looks stupid, however there is a non-perfect workaround and that is to size the control so that it only covers the square and have no associated text. Then add a second control for the text. The disadvantage is that clicking on the text doesn't toggle the checkbox.