将命令行参数传递给WiX自定义操作

时间:2019-02-26 18:14:26

标签: wix exe command-line-arguments custom-action

我们有一个通过Windows安装程序(msi)安装的桌面应用程序,并且我们希望添加自定义操作,以便在将LAUNCH_APP=1传递给cmd时重新启动.exe。

所以我有一个vbs脚本,该脚本会启动一个bat文件,该文件会启动安装msi(主要升级):

vbs脚本:

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

蝙蝠脚本:

@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

在我的wix安装程序(wix版本3.1.0)中具有以下自定义操作:

<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>

我不知道如何在自定义操作中添加参数(例如—new-version)以重新启动我的exe。

最后,我想运行命令:

Lifen.exe —new-version

我尝试了多种写法:

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

,或者在阅读了此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"'

有人有想法吗?

预先感谢

1 个答案:

答案 0 :(得分:2)

基本语法

<Property Id="WixQuietExecCmdLine" Value='"[INSTALLFOLDER]Lifen.exe" --new-version'/> 
  • 您始终需要引用路径,因为它们可能包含空格。
  • 在文件夹属性后不需要反斜杠,例如[INSTALLFOLDER],因为MSI运行时确保所有安装文件夹属性的值都以反斜杠结尾。
  • 与参数相同,如果它们可能包含空格,则需要引用。如果您有一个像--new-version这样的常量参数,可以确定没有空格,则无需引用。对于包含属性引用的参数,始终引用会更安全。例如:

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

如有疑问,请查看详细日志,以查看WixQuietExecCmdLine的实际值是否符合您的期望。通过调用msiexec -l*v logfile.txt <OtherParameters>激活详细日志记录。

64位可执行文件

要运行64位可执行文件,请改用WixQuietExec64自定义操作和WixQuietExec64CmdLine属性。