Parameters for WiX's ExePackage and InstallCommand

4

I have an executable that requires a preset of parameters being passed to it, hence the need for a batch file (.bat). All was working well until I figured that the folder path used in [WixBundleLastUsedSource] could contain a space.

Here is the EXE file packaged definition:

<ExePackage Id="myexepackage" Compressed="no" Permanent="yes" Cache="no"    
            After="previousfeature"
            SourceFile="$(var.preprocessorvariable)\myexe.bat"
            InstallCommand="[WixBundleLastUsedSource]myexe.exe [otherparam]" />

And here are some test I tried and the logs from them:

This one is the working variation:

Applying execute package: myexepackage, action: Install, path: C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat, arguments: '"C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat" C:\Users\user\Desktop\Install\myexe.exe otherparamvalue'

While the following two logs are from failures:

Applying execute package: myexepackage, action: Install, path: C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat, arguments: '"C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat" "C:\Users\user\Desktop\Install\myexe.exe" otherparamvalue'

Applying execute package: myexepackage, action: Install, path: C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat, arguments: '"C:\ProgramData\Package Cache\7AE3BA856B7D415569854BFE32DD3848112B7BFA\myexe.bat" "C:\Users\user\Desktop\Install new\myexe.exe" otherparamvalue'

Whenever I introduce quotes to the EXE file package with either " or %quot; like

<ExePackage Id="myexepackage" Compressed="no" Permanent="yes" Cache="no" 
            After="previousfeature"
            SourceFile="$(var.preprocessorvariable)\myexe.bat"
            InstallCommand="&quot;[WixBundleLastUsedSource]myexe.exe&quot;[otherparam]" />

it fails with:

e000: Error 0x80070001: Process returned error: 0x1
e000: Error 0x80070001: Failed to execute EXE package.
e000: Error 0x80070001: Failed to configure per-machine EXE package.

Is there a solution or workaround for this?

parameters
wix
exe
asked on Stack Overflow Jun 14, 2013 by user2485350 • edited Jun 20, 2020 by Community

3 Answers

1

The InstallCommand attribute should contain the parameters passed to the exe. It shouldn't contain the .exe itself.

answered on Stack Overflow Jun 14, 2013 by BryanJ
0

I had this happening to me because the Wix value passed in ended in a backslash. This ended up causing the second double quote to be escaped somewhere in the install engine, and as a result, the first quote was being stripped. For example:

<ExePackage SourceFile="..\bin\MyEXE.exe" Name="MyEXE.exe" InstallCommand="&quot;InstallDir=[INSTALLDIR]&quot; InstallType=MyType" />

When [InstallDir] ended in a backslash, instead of two command line args there was one, and the first " was being stripped off. The "fix" was to add a space before the second ":

<ExePackage SourceFile="..\bin\MyEXE.exe" Name="MyEXE.exe" InstallCommand="&quot;InstallDir=[INSTALLDIR] &quot; InstallType=MyType" />

Unfortunately some EXE packages might have a problem with the trailing space so this fix might not work for everyone.

answered on Stack Overflow Jan 22, 2019 by Ed Bayiates
0

My experience with WiX 3.11.1 is that when providing the command parameters via InstallCommand or UninstallCommand, any double quotation marks will cause the command processor (i.e., cmd.exe) to fail. Passing double quotation marks can be tricky from batch script to batch script, let alone encoded in XML inside of WiX. It is probably possible to figure out the correct set of backslashes or other escape characters to place in front of each &quot; tag, but I decided to bypass that completely.

My solution was to use single quotes and modify the batch script to replace all single quotes with double quotes before executing it. Other characters could be used.

<ExePackage Id="myexepackage" Compressed="no" Permanent="yes" Cache="no" 
  After="previousfeature"
  SourceFile="$(var.preprocessorvariable)\myexe.bat"
  InstallCommand="'[WixBundleLastUsedSource]myexe.exe' [otherparam]" />

And myexe.bat is something like:

Set CommandText=%*
Set CommandText=%CommandText:'="%
Call %CommandText%
answered on Stack Overflow May 7, 2019 by melacore

User contributions licensed under CC BY-SA 3.0