Neil
Neil

Reputation: 5239

Is it possible to have a batch file as a binary element type in Wix?

Here's my wix

<Binary Id="B.RenameFiles" SourceFile="RenameFiles.bat"/>
<CustomAction Id="CA.RenameFiles" BinaryKey="B.RenameFiles"
              ExeCommand="RenameFiles.bat" Execute="immediate" Return='ignore'/>

<InstallExecuteSequence>
    <Custom Action="CA.RenameFiles" Before="InstallValidate"></Custom>
</InstallExecuteSequence>

This doesn't work and spits out an error in the msi log "A program required for this install to complete could not be run". I'm not really sure if this is possible or if binary is only for use with exe's and dll's etc.

The way i'm doing it at the moment is to install the bat file and then run it from there but it would be neater if I could use it as a binary instead and not install it on the local machine.

Thanks Neil

Upvotes: 3

Views: 2018

Answers (2)

MarcusUA
MarcusUA

Reputation: 394

Agree with Cosmin, you cannot execute BAT from binary, however you can launch it (almost) at any time during installation with help of "CMD.exe /C " custom action, and even have it run hidden (without cmd.exe window), i.e. for deffered CA one can use:

<CustomAction Id="Set_CA_HiddenBAT" Property="CA_HiddenBAT" Value="&quot;cmd.exe&quot; /c &quot;[DirectoryWhereBatFileInstalled]Your.bat&quot;" />
<CustomAction Id="CA_HiddenBAT" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="yes" />

Or if you want it visible:

<CustomAction Id="CA_LaunchBAT" Directory="DirectoryWhereToExecute" ExeCommand="CMD.exe /c &quot;[DirectoryWhereBatFileInstalled]Your.bat&quot;" Return="ignore" />

Note: Remember to run CA_HiddenBAT / CA_LaunchBAT after InstallFiles action and have added WixUtilExtension to your .wixproj:

<LinkerAdditionalOptions>-ext WixUtilExtension</LinkerAdditionalOptions>
<CompilerAdditionalOptions>-ext WixUtilExtension</CompilerAdditionalOptions>

There's also a way to launch BAT before InstallFile action, but this is tricky, let me know if you need this.

Upvotes: 2

Cosmin
Cosmin

Reputation: 21416

BAT files cannot be launched directly by Windows Installer custom actions. You need a custom action which uses ShellExecute to launch your BAT.

So you can't use a BAT as a Binary custom action.

Upvotes: 5

Related Questions