Here’s a really simple tutorial about running batch files from a Wix installation package. I have spent days of my life trying to work out how to run a batch file from my Wix msi installation. All of the examples online stop short of actually being useful and are written by users with lots of experience and they miss out the important steps. Here is a short, concise, and hopefully easy to follow guide to running a batch file in a WiX installation script.
The basic premise is as follows:
1) WiX installer copies files to hard disk location specified during install script.
2) The included batch file is placed in a known child folder in the install path.
3) How do you run the batch file using the TargetPath that it has just been installed to.
The biggest issue that I came across was specifying the full path/folder to the batch file to run. To do this you must include the batch file as part of your Installation hierarchy as follows:
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='MyInstallFolder' Name='XXX'>
</Directory>
</Directory>
</Directory>
Next step is to identify the list of files that are to be included. For the sake of this example I have just used the single batch file that we are wanting to run. The following code picks up the Batch file from the location specified by the ‘Source’ attribute and puts it in the location ‘C:\Program Files\XXX’
<DirectoryRef Id="MyInstallFolder">
<Component Id="BatchComponents" Guid="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
<File Id='my_batch_script' Name='MyBatch.bat' DiskId='1' Source='' />
</Component>
</DirectoryRef>
OK, we’ve now setup the script to include a single batch file and we’ve also told it where to put the batch file on the target machine. We now need to setup a CustomAction using the CAQuietExec function. This customer action will execute the batch file and we can specify the TargetPath using the following code.
<CustomAction Id="BatchCmd" Property="BatchRun" Value=""[#my_batch_script]"" Execute="immediate"/>
<CustomAction Id="BatchRun" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="yes"/>
The value in bold sets the path to be the same as the target path for the batch file and you link the BatchCmd CustomAction to the BatchRun CustomAction by using the same id in the Property field.
Finally we now need to tell the installer to run the batch file for us.
<InstallExecuteSequence>
<Custom Action="BatchCmd" Before="BatchRun">NOT INSTALLED</Custom>
<Custom Action="BatchRun" After="InstallFiles">NOT INSTALLED</Custom>
</InstallExecuteSequence>
That’s it. When your script runs it will run the batch file after it has installed it. You can change the ‘NOT INSTALLED’ string to other values to specify whether the batch file runs on install/un-install/other.
Hope this helps because it took me ages to find a simple example for running a batch file from WiX Installer