Executing Commands as Custom Actions in WiX

<CustomAction Id="SetCommand"
              Property="CommandId"
              Value="&quot;command&quot; -p &quot;some parameter with spaces&quot;"
              Execute="immediate"/>
<CustomAction Id="CommandId"
              BinaryKey="WixCA"
              DllEntry="CAQuietExec"
              Execute="deferred"
              Return="check"/>
...
<InstallExecuteSequence>
    <Custom Action="SetCommand" After="CostFinalize"/>
    <Custom Action="CommandId" After="InstallExecute"/>
</InstallExecuteSequence>

The two Custom Actions work together to execute an arbitrary command. The first Custom Action sets the actual thing you want to execute as a property and the second executes it. You need to follow this pattern if your command relies on other installer properties. The Property name must be the same as the id of the second Custom Action and the actual executable needs to be in quotes!

The CAQuietExec function will execute your command without opening a command prompt. It’s part of the WixUtilExtension.

Tagged with: ,
Posted in WiX

Leave a comment