gpt4 book ai didi

Wix 每个用户安装程序以检测 Visual C++ 2015 Redistributable

转载 作者:行者123 更新时间:2023-12-04 11:45:38 57 4
gpt4 key购买 nike

我正在创建一个 .msi 安装程序,它必须确定系统中是否存在 Visual C++ 2015 Redistributable,如果没有,则使用自定义消息中断安装。官方 Wix 文档指的是 VC++ 的实际安装,我不希望这样做,因为我的安装程序是“每个用户”,还有其他几个 stackoverflow 问题是指包而不是 .msi http://wixtoolset.org/documentation/manual/v3/howtos/redistributables_and_install_checks/install_vcredist.html .
Wix Burn vcredist , WIX check if VS2015 C++ redistributable is installed , https://gist.github.com/nathancorvussolis/6852ba282647aeb0c5c00e742e28eb48

所以我想问题是,如何有效地检测每个用户安装程序中 Visual C++ 2015 Redistributable 的存在。

最佳答案

The latest supported Visual C++ downloads



运行时检测方法
我可以找到几种方法来检测 的存在Visual C++ 运行时 .
  • 注册表
  • VCRedist 安装程序使用的 key (请参阅下面的部分)
  • Keys mentioned in my original answer - grabbed from this old answer

  • 文件存在和版本检查
  • 检查是否存在核心运行时文件
  • 请参阅下面的单独部分

  • MSI API
  • 您可以通过查找产品 GUID
  • 来检测是否安装了特定的 MSI。
  • 可靠,但难以跟踪所有产品 GUID(不同版本)
  • 更新 :您也可以使用如下所述的升级代码。它应该在发布和更新之间保持稳定(对于每个主要版本,也可能在主要版本之间)。

  • 摔倒EXE?
  • 建议根据运行时使用 EXE
  • 启动它并失败意味着运行时不存在或损坏


  • 好与坏 - 评价 : Option 1 似乎很容易受到攻击,因为部署运行时的合并模块变体可能不会写入这些 key 。 Option 3 可能工作得很好,但很难跟踪所有 GUID。 Option 4 基于较新的运行时删除某些注册表项,似乎已经失败。虽然现在已经修复,但这可能会重新出现。

    文件版本存在/版本检查
    我看的越多,我就越开始认为您必须检查实际文件本身,并可能检查正确的文件版本。文件 vcruntime140.dll System32 文件夹(64 位版本)和 SysWOW64 文件夹(32 位版本)? See files list towards bottom here .
    只需添加一个链接以确保安全。
  • How to detect the presence of the Visual C++ 2012 redistributable package?
  • Redistributing Visual C++ Files

  • 测试 VBScript - 仅用于测试目的(脚本有时会被防病毒软件阻止):
    Set fso = CreateObject("Scripting.FileSystemObject")
    MsgBox fso.GetFileVersion("C:\Windows\System32\vcruntime140.dll")
    您可以使用 检测文件存在和版本应用搜索在 MSI 文件中。

    下面是我写的其他一些东西,只是留下来。

    VCRedist
    看来 Visual C++ 可再发行包 ( VCRedist_x86.exe , VCRedist_x64.exe ) - 这是部署运行时的推荐方式 - 检查以下注册表项以确定实际安装的运行时版本
    HKLM\SOFTWARE\Microsoft\VisualStudio\<version>\VC\Runtimes\

    子键 x86 x64 似乎都包含设置为 的“ Installed ”值1 安装运行时时。我会假设 - 没有时间测试这一切 - 然后你可以检查:
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64 Installed = 1
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86 Installed = 1

  • 合并模块 : 经过简单的检查,看起来这些值不是由也可用于分发此运行时的合并模块写入的。我现在没有时间或手段来正确检查这个。
    令人惊讶的是,运行时的 2015 版和 2017 版都写入了 14.0 key - 因为它们是二进制兼容的。 如果安装了 2017 版本,则 VCRedist 可执行文件将返回错误,因为不需要安装。确实很奇怪。但就你的目的而言,这应该不是重点。 Source .

    MSI API - 检索产品代码
  • Mailbag: How to detect the presence of the VC 8.0 runtime redistributable package
  • Updated VC 8.0 runtime redistributable packages are included in Visual Studio 2005 SP1
  • How can I find the product GUID of an installed MSI setup?

  • UPDATE: installer.ProductState - normal installed state is 5:

    I forgot about the ProductState property when writing the below.You can check for an installed product with two lines of code if youhave the actual product code:

    Dim installer : Set installer = CreateObject("WindowsInstaller.Installer")
    MsgBox installer.ProductState("{00000000-0000-0000-0000-000000000001}")

    这里还有另一种方法: MSDN: How to programmatically check for the presence of a Windows Installer-based product by using its product code .

    Tip: I wouldn't use this approach seeing as the product code changes frequently when products are updated. Hence I like better tocheck for file versions of core-runtime files. This seems morereliable for the future (provided version parsing is done correctlyand reliably - don't roll your own).



    样机 :
    Public installer
    Set installer = CreateObject("WindowsInstaller.Installer")

    ' Don't have the 2015 GUID
    VC2015 = CheckForProductCode("{00000000-0000-0000-0000-000000000000}")
    VC2017 = CheckForProductCode("{C77195A4-CEB8-38EE-BDD6-C46CB459EF6E}")

    MsgBox "VC2015: " & CStr(VC2015) & vbCrLf & "VC2017: " & CStr(VC2017)

    Function CheckForProductCode(productcode)

    CheckForProductCode = False

    For Each product In installer.ProductsEx("", "", 7)
    If(LCase(productcode) = LCase(product.ProductCode)) Then
    CheckForProductCode = True
    Exit For
    End If
    Next

    End Function
    更新基于 Zett42's suggestion枚举共享相同升级代码的产品:
    Set installer = CreateObject("WindowsInstaller.Installer")

    ' Enumerate all products related to "Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148"

    ' {AA783A14-A7A3-3D33-95F0-9A351D530011} is the upgrade code
    Set upgrades = installer.RelatedProducts("{AA783A14-A7A3-3D33-95F0-9A351D530011}")
    For Each u In upgrades
    MsgBox u, vbOKOnly, "Product Code: "
    Next

    部署 Visual Studio C++ 运行时
    除了检测之外,还有几种分发 Visual Studio C++ 运行时的方法:
  • 静态链接
  • Visual C++ 可再发行包
  • VCRedist_x86.exe , VCRedist_x64.exe , 或 VCRedist_arm.exe
  • Program Files(x86)\Microsoft Visual Studio\2017\edition\VC\Redist\MSVC\lib-version

  • 可再发行合并模块 ( .msm files )
  • 对某些用途来说不够( 通用 CRT ):
  • Redistributables for deploying C++ exe developed with Visual Studio 2015 on Windows 7
  • WIX merge c++ runtime


  • 本地应用文件夹
  • 将 DLL 复制到本地应用程序文件夹
  • 出于服务原因(更新、安全修复)不推荐使用


  • 安全保存链接 :
  • Redistributables for deploying C++ exe developed with Visual Studio 2015 on Windows 7
  • How to detect whether I need to install VCRedist?
  • WIX merge c++ runtime
  • How to detect if Visual C++ 2017 Redistributable is installed

  • 旧答案
    有这个老帖子。我不太喜欢直接读取注册表,让我看看是否能找到更可靠的方法,但同时也可以看看: Detect if Visual C++ Redistributable for Visual Studio 2012 is installed
    再多一个链接,如何查找已安装产品的Windows Installer 产品代码: How can I find the product GUID of an installed MSI setup?

    关于Wix 每个用户安装程序以检测 Visual C++ 2015 Redistributable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53638587/

    57 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com