Pass command-line arguments to WiX custom action

时光毁灭记忆、已成空白 提交于 2020-07-21 03:25:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/54891721/pass-command-line-arguments-to-wix-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!