You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wix 3升级至Wix 5后CustomAction执行批处理失败求助

Wix 4/Wix 5 调用批处理文件失败排查

背景

原Wix 3安装程序通过以下配置可成功执行批处理文件:

<SetProperty Id="RunBatch" Value="&quot;[SetupDir]batch.bat&quot;"
    Before="RunBatch" Sequence="execute" />
<CustomAction Id="RunBatch" Execute="deferred" 
    Return="check" Impersonate="no" BinaryKey="WixCA" DllEntry="WixQuietExec64" />

<InstallExecuteSequence>
    <Custom Action="RunBatch" Before="RunDBSetup" >
        NOT Installed AND NOT REMOVE
    </Custom>
</InstallExecuteSequence>

迁移到Wix 4(Wix 5兼容架构)后,配置被转换为:

<SetProperty Id="RunBatch" Value="&quot;[SetupDir]batch.bat&quot;"
    Before="RunBatch" Sequence="execute" />
<CustomAction Id="RunBatch" Execute="deferred"
    Return="check" Impersonate="no" DllEntry="WixQuietExec" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" />

<InstallExecuteSequence>
    <Custom Action="RunBatch" Before="RunDBSetup" Condition="NOT Installed AND NOT REMOVE" />
</InstallExecuteSequence>

运行msiexec时出现以下错误:

MSI (s) (5C:E8) [19:05:48:239]: Executing op: ActionStart(Name=RunBatch,,)
MSI (s) (5C:E8) [19:05:48:242]: Executing op: CustomActionSchedule(Action=RunBatch,ActionType=3073,Source=BinaryData,Target=WixQuietExec,CustomActionData="C:\Program Files\Company\Product\setup\batch.bat")
MSI (s) (5C:E8) [19:05:48:244]: Creating MSIHANDLE (165) of type 790536 for thread 9192
MSI (s) (5C:3C) [19:05:48:246]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI5719.tmp, Entrypoint: WixQuietExec
MSI (s) (5C!1C) [19:05:48:252]: Creating MSIHANDLE (166) of type 790531 for thread 15644
WixQuietExec:  Error 0x80070002: Command failed to execute.
MSI (s) (5C!1C) [19:05:48:253]: Closing MSIHANDLE (166) of type 790531 for thread 15644
MSI (s) (5C!1C) [19:05:48:253]: Creating MSIHANDLE (167) of type 790531 for thread 15644
WixQuietExec:  Error 0x80070002: QuietExec Failed
MSI (s) (5C!1C) [19:05:48:254]: Closing MSIHANDLE (167) of type 790531 for thread 15644
MSI (s) (5C!1C) [19:05:48:254]: Creating MSIHANDLE (168) of type 790531 for thread 15644
WixQuietExec:  Error 0x80070002: Failed in ExecCommon method
MSI (s) (5C!1C) [19:05:48:255]: Closing MSIHANDLE (168) of type 790531 for thread 15644
CustomAction RunBatch returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)

已尝试以下操作但未解决问题:

  • 确认批处理文件直接在cmd中运行正常
  • 使用仅含echo语句的简化批处理,末尾添加exit 0测试
  • 分别指定Wix4UtilCA的X86和X64版本
  • 设置Impersonate="yes"
  • 以管理员权限从PowerShell运行安装程序

可能的原因及修复方案

1. WixQuietExec调用方式变更

Wix 4的WixQuietExec不再像Wix 3那样自动通过cmd.exe解析批处理文件,需要显式调用cmd来执行bat文件。修改SetProperty的Value为:

<SetProperty Id="RunBatch" Value="&quot;cmd.exe&quot; /c &quot;[SetupDir]batch.bat&quot;"
    Before="RunBatch" Sequence="execute" />

这样确保系统通过命令行解释器来执行批处理,而非直接调用bat文件。

2. 延迟自定义操作的属性可用性

延迟自定义操作无法直接访问普通安装属性,需确认SetupDir是否已被正确传递到延迟上下文。可以验证CustomActionData中的路径是否正确(从日志看路径是对的,但仍需确认该路径在执行自定义操作时是否已存在)。如果SetupDir是自定义属性,需确保它在InstallExecuteSequence执行到RunBatch前已被正确设置。

3. Wix4UtilCA架构匹配问题

检查$(sys.BUILDARCHSHORT)是否正确解析为x86或x64。如果安装包是跨架构的,可能需要显式指定对应架构的Wix4UtilCA,或者改用不带架构后缀的Wix4UtilCA(如果版本支持)。

4. 文件权限与路径问题

虽然直接运行批处理正常,但延迟自定义操作以SYSTEM账户执行,需确认批处理文件及所在目录的NTFS权限是否允许SYSTEM用户读取和执行。此外,检查路径是否存在隐形字符或大小写问题(Windows通常不敏感,但极端场景下可能影响)。

5. 启用详细日志排查

运行安装程序时添加详细日志参数:

msiexec /i 你的安装包.msi /l*v install.log

查看日志中WixQuietExec的更多输出,可能会暴露具体的错误细节,比如文件找不到的真实原因。

内容的提问来源于stack exchange,提问作者rmendel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 23:16:03