Batch File Custom Actions |
A batch file is not an executable file so it must be executed via the appropriate command process for the operating system ("command.com" or "cmd.exe").
The "/c" option tells the command processor to return after executing the command. The example below checks for return code, you may or may not want to ignore any return code.
You will notice the "hack" that is required for WINNT+, this should not be required for "command.com". The "VersionNT" and "Version9X" are some of the "properties" that you can use in the custom action's condition.
You will probably also wish to test the generated MSI on multiple operating systems and the use of "virtual machines" is probably the best way of doing this.
<$Component "BatchFile" Directory_="INSTALLDIR"> ;--- Create Our Batch file (obviously you may already have one) --------- #define OurBatchFile_SN LaunchedAtEnd.BAT #define OurBatchFile <$MAKEMSI_OTHER_DIR>\<$OurBatchFile_SN> <$FileMake "<$OurBatchFile>"> @echo off #( .\MsgBox.exe /II "EXECA for .BAT" "Hi there. A batch file invoked by the ExeCa command (product '<$ProdInfo.ProductName> version <$ProductVersion>) is displaying this message. The Installation directory is '%1'." #) @rem pause <$/FileMake> ;--- Add the batch file ------------------------------------------------- <$File Source="<$OurBatchFile>" KeyPath="Y"> ;--- Our batch file will invoke this (to make it obvious it was called etc) --- <$File Source="D:\DBAREIS\tools\MsgBox.exe"> <$/Component> ;--- Invoke the batch file (probably work in WinNT/Win2000/WinXP) ----------- #define CmdExeFix " ;;CMD.EXE "feature". Thanks MS... #( <$ExeCa EXE=^cmd.exe^ ;;NOTE: "Command.com needed for Win95-WinME" Args=^/c <$CmdExeFix>"[INSTALLDIR]<$OurBatchFile_SN>" "[INSTALLDIR]"<$CmdExeFix>^ WorkDir="INSTALLDIR" ;;Current directory MUST be MSGBOX directory! Condition=^<$CONDITION_EXCEPT_UNINSTALL> and VersionNT^ ;;Install or Repair, note: not checking if silent or not here! Seq="StartServices-" Type="AnyRc" ;;Best if the batch file sets the return (exit) code to zero when OK and nonzero otherwise but if not... > #)
In the above we used the "AnyRc" attribute to tell windows installer that the batch file doesn't return meaningful return codes, this however means that the task may have failed and you won't detect this, if you'd rather the batch file tell Windows Installer when it succeeds then see the "Meaningful Return Code" tip.