0

我正在编写一个安装程序,其中还包含使用 WIX 构建的 MSI 包。我在运行 msiexec 后检查返回代码并跳过一些错误代码。例如,当返回码为 1638(产品已安装)时,用户不应收到错误消息

但是当安装旧版本的产品时,返回码是 1603(未知错误)。我也想跳过这种情况(用户已经获得更新版本)

蜡码是

<Upgrade Id="<GUID>">
    <UpgradeVersion Minimum="$(var.product_version)" OnlyDetect="yes" Property="NEWERFOUND" />
    <UpgradeVersion Minimum="0.1.0" IncludeMinimum="yes" Maximum="$(var.product_version)" IncludeMaximum="no" Property="SELFFOUND" />
</Upgrade>

<MajorUpgrade DowngradeErrorMessage=You have installed newer version $(var.product_name)." />

问题是当 SELFFOUND 或 NEWERFOUND 属性被激活时,我如何才能返回另一个代码而不是 1603

更新:我不想影响返回码,我想得到适当的代码而不是一般的致命错误

4

1 回答 1

2

您无法控制msiexec.exe. 它的返回代码已记录在案,并且列表很全面。该服务根据安装状态确定退出代码。

更新:我唯一能建议的是直接使用数据库函数:

  1. MsiOpenPackage, 和
  2. MsiDoAction("FindRelatedProducts")运行将通过处理升级表FindRelatedProducts来评估SELFFOUNDNEWERFOUND属性的操作。
  3. 然后用 分析属性MsiGetProperty
  4. 用 关闭包MsiCloseHandle

使用获得的 和 的值SELFFOUNDNEWERFOUND您可以决定是否需要安装产品。如果是,您可以运行msiexec.exe或使用MsiInstallProduct.

Disclamer: I have never tried to do anything like this, and I am not sure it will work. It should, yet it does not look easy.

于 2012-07-09T18:48:35.727 回答