Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass command-line arguments to WiX custom action

We have a desktop application installed through a windows installer (msi), and we want to add a custom action that relaunches the .exe when we have pass LAUNCH_APP=1 to the cmd.

So I have a vbs script that launch a bat file that launch install the msi (major upgrade):

vbs script:

Set WshShell = CreateObject("WScript.Shell")
Const TemporaryFolder = 2
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim tempFolder: tempFolder = fso.GetSpecialFolder(TemporaryFolder)
WshShell.Run chr(34) & WScript.Arguments(0) & chr(34) & chr(32) & chr(34) & tempFolder & "\Lifen\update\LifenInstaller.msi" & chr(34) & chr(32) & chr(34) & WScript.Arguments(1) & chr(34), 0, True
Set WshShell = Nothing

bat script:

@echo off 

call :start >%APPDATA%\Lifen\batMsiLog.log

:start
wmic process where "name='Lifen.exe'" delete
start /wait msiexec /i %1 /qn /norestart /log %APPDATA%\Lifen\msilog.log LAUNCH_APP=1

And in my wix installer (wix version 3.1.0) has this custom action:

<Property Id="WixQuietExecCmdLine" Value='"[INSTALLFOLDER]\Lifen.exe"'/>
<CustomAction Id="QtExecRestartApp" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="immediate" Return="check"/>
<InstallExecuteSequence>
  <Custom Action="QtExecRestartApp" After="InstallFinalize">LAUNCHAPP = 1</Custom>
</InstallExecuteSequence>

I don't know how to add an argument (like —new-version) to my custom action to relaunch my exe.

In the end, I would like to run the command:

Lifen.exe —new-version

I tried various ways to write it:

  • '"[INSTALLFOLDER]\Lifen.exe --new-version=x.x.x"'
  • '"[INSTALLFOLDER]\Lifen.exe" "--new-version=x.x.x"'

or also after reading this stackoverflow : How to add arguments to the custom action exe in Wix?

  • '"&quot;[#"[INSTALLFOLDER]\Lifen.exe"]"&quot; "--new-version"'
  • '"&quot;[#"[INSTALLFOLDER]\Lifen.exe"]"&quot; "--new-version"'

Does anyone have an idea ?

Thanks in advance

like image 964
Valentine Langer Avatar asked Oct 25 '25 11:10

Valentine Langer


1 Answers

Basic Syntax

<Property Id="WixQuietExecCmdLine" Value='"[INSTALLFOLDER]Lifen.exe" --new-version'/> 
  • You always need to quote paths, because they may contain spaces.
  • You don't need a backslash after folder properties like [INSTALLFOLDER], because the MSI runtime makes sure that the values of all installation folder properties end with backslash.
  • Same for the arguments, you need to quote if they may contain spaces. If you have a constant argument like --new-version where you know for sure that there are no spaces, you don't need to quote. For arguments that contain property references, it's safer to always quote. E. g.:

    <Property Id="WixQuietExecCmdLine" Value='"[INSTALLFOLDER]Lifen.exe" "--new-version=[NEWVERSION]"'/> 
    

If you are in doubt, have a look into the verbose log to see if the actual value of WixQuietExecCmdLine is what you expect. Activate verbose logging by calling msiexec -l*v logfile.txt <OtherParameters>.

64-Bit Executables

To run 64-bit executables, use the WixQuietExec64 custom action and WixQuietExec64CmdLine property instead.

like image 105
zett42 Avatar answered Oct 27 '25 00:10

zett42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!