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

Wix自定义动作问题:仅在特定注册表不存在时安装VC Redist

问题:无论注册表状态如何,VC Redist安装自定义动作始终执行

我已经折腾了10小时,试过各种方法,但就是没法实现需求——只有当系统未安装指定版本VC Redist时才执行自定义安装动作,可现在不管注册表中有没有对应项,这个自定义动作都会跑起来。

原代码片段

<Fragment>
    <util:RegistrySearch Id="VC_REDIST_Version"
      Root="HKCR"
      Variable="VCREDIST143431931"
      Key="Installer\Dependencies\VC,redist.x86,x86,14.34,bundle"
      Format="raw" 
      Value="Version"
      Result="value" />    

    <ComponentGroup Id="ThirdPartyComponents" Directory="ExtSources">
      <Component Id="Component_VC_redist_x86" Guid="2B80F89A-990A-438E-A475-9E72d8A0198A" >
        <File Id="ExtSources_VC_redist.x86.exe" Name="VC_redist.x86.exe" Source="$(var.xxxxx_TargetDir)ExtSources\VC_redist.x86.exe" />
      </Component>
    </ComponentGroup>

    <CustomAction Id="Install_VC_redist_x86"
      Execute="immediate"
      Impersonate="no"
      Return="asyncNoWait"
      FileKey="ExtSources_VC_redist.x86.exe"
      ExeCommand="" />

      <InstallExecuteSequence>
        <Custom Action="Install_VC_redist_x86" After="InstallFinalize">NOT VCREDIST143431931</Custom>
      </InstallExecuteSequence>

  </Fragment>

问题原因

原代码的核心问题在于:

  • 使用util:RegistrySearch直接绑定变量的方式,可能导致注册表搜索结果未被WiX的条件判断逻辑正确识别,或搜索时机不对导致变量始终为空
  • 未指定Win64属性,在64位系统中可能搜索到错误的注册表分支,无法获取正确版本值
  • 条件仅简单判断NOT VCREDIST143431931,未考虑版本值的有效性和比较逻辑,即使搜索到版本也可能因格式问题触发条件

更新:可行代码(实现版本判断跳过安装)

调整后的代码可实现:当系统已安装相同或更新版本的VC Redist时,自动跳过安装动作。

<Fragment>
    
    <Property Id="VCREDISTINSTALLED">
      <RegistrySearch Id="VCRedistInstalledSearch"
                      Root="HKCR"
                      Key="Installer\Dependencies\VC,redist.x86,x86,14.34,bundle"
                      Name="Version"
                      Type="raw" 
                      Win64="no"/>
    </Property>

    <ComponentGroup Id="ThirdPartyComponents" Directory="ExtSources">
      <Component Id="Component_VC_redist_x86" Guid="2B80F89A-990A-438E-A475-9E72d8A0198A" >
        <File Id="ExtSources_VC_redist.x86.exe" Name="VC_redist.x86.exe" Source="$(var.xxxxx_TargetDir)ExtSources\VC_redist.x86.exe" />
      </Component>
    </ComponentGroup>

    <CustomAction Id="Install_VC_redist_x86"
      Execute="immediate"
      Impersonate="no"
      Return="asyncNoWait"
      FileKey="ExtSources_VC_redist.x86.exe"
      ExeCommand="/quiet /norestart" />

      <InstallExecuteSequence>
        <Custom Action="Install_VC_redist_x86" After="InstallFinalize"><![CDATA[VCREDISTINSTALLED < "14.34.31931.0" AND NOT REMOVE]]></Custom>
      </InstallExecuteSequence>

  </Fragment>

关键调整点

  • 将注册表搜索嵌套在<Property>标签内,确保搜索结果正确绑定到属性,WiX可正常识别用于条件判断
  • 添加Win64="no"明确指定搜索32位注册表分支,避免系统位数导致的搜索偏差
  • 优化条件判断逻辑:通过版本比较VCREDISTINSTALLED < "14.34.31931.0"确保仅在安装版本低于目标版本时执行,同时加上AND NOT REMOVE避免卸载时触发安装动作
  • 给VC Redist安装命令添加/quiet /norestart参数,实现静默安装且不强制重启

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 16:35:24