MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: VBSCRIPT Subroutines in BATCH files[Next]: Magic Tweeks
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Custom Actions

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.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: VBSCRIPT Subroutines in BATCH files[Next]: Magic Tweeks


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday February 28 2016 at 3:45pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.