Monday, July 23, 2012

WiX Custom Action - Copy MSI after Install

In WiX there is a functionality to execute application after successfully closing the setup in async mode.
Add following in the .wxs file and execute candle.exe with usual commands.

<Property Id="WixShellExecTarget" Value="[CommonAppDataFolder]Product_Data\test.exe" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
   <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">NOT Installed</Publish>

In command line compilation for Light.exe following "-ext" needed to add.
These extensions will allow use of WixUIExtension.dll and WixUtilExtension.dll.

light.exe d:\abc\test.wixobj -ext WixUIExtension -ext WixUtilExtension -out d:\abc\test.msi

This is the basic logic behind executing any exe after completing setup. This application executes in async mode and in my case I have used it to copy the present MSI from its present location to program data for safekeeping. This copy MSI is a simple implementation of copying file from one location to another hence not including that code here.