Answer

Windows Installer cannot launch batch files directly by using installed or attached custom actions. However, in Advanced Installer you can run a CMD or BAT file through a Launch file or open URL predefined custom action. In the case of a 64-bit CMD or BAT file you can use another predefined custom action called Launch file or open URL Using a 64-bit Launcher.

Since the files cannot be attached to the MSI, they need to be present on the target machine when the custom action runs. This can be done in two ways:

  • Add the CMD or BAT file in the Files and Folders page. This way the file will be installed by the package and it can be launched after the Install Execution Stage -> Add Resources action group. In this case the custom action should be set as "Deferred" in the Custom Action Properties page to make sure it can access the installed file.
  • Another approach is to add the CMD or BAT file as a temporary file. This way, the file is copied on the target machine after the Wizard Dialogs Stage -> Paths Resolution -> CostFinalize standard action and removed after Install Execution Stage -> Finish Execution -> InstallFinalize. In this case the custom action can use any execution option.

After the file is added in the "Files and Folders" page, you can configure the custom action. The "Launch file or open URL" custom action uses a custom tool named "viewer.exe" to launch the batch file. Therefore, this custom action's "Source Path" should always be set to:

<AI_CUSTACTS>viewer.exe

In the case of the "Launch file or open URL Using a 64-bit Launcher" custom action, the batch file is launched by a 64-bit "viewer.exe" tool. In this case the "Source Path" should be set to:

<AI_CUSTACTS64>viewer.exe

The "Source Type" should be:

Executable (*.exe)

The Command Line field should contain the full path of the file you want to launch. You can add a reference to your batch file by using the [ Edit... ] button next to the field. For example, if the file is called "MyBatchFile.bat" and it is added as a regular file, the custom action's command line would be:

"[#MyBatchFile.bat]"

For a temporary file, the command line would look like this:

"[&MyBatchFile.bat]"

NoteThe reference to the batch file is enclosed by quotes to make sure its path is recognized even if it contains spaces.

ImportantThis field is of Formatted Type and it can be edited using Smart Edit Control.

The "Expression" field in the Custom Action Properties page should contain the custom action's condition. Edit this field using Smart Condition Edit Control.

Caution!A custom action which doesn't have a condition will run in every installation process: first time install, uninstall, repair, modification.