There are 3 different (but very similar) registry keys for each of the 3 platform packages. Each key has a DWORD value called “Installed” with a value of 1.
There is no installcheck element in the bootstrapper package manifest shipped with Visual C++. Guess Microsoft wants to always install if you set it as a prerequisite.
if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86","Installed") = 0 Then
if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes\x86","Installed") = 0 Then
这种复杂性来自于这样一个事实: 有许多 VC 运行时修订版,这可能会导致这样的情况: 尽管安装了 VC10运行时,但它们的版本号不够新,所以你的 EXE 不会启动,除非你要么安装非常精确的运行时,你所需要的或一个较新的运行时,使这个版本和以前的版本相同的主要版本运行(并排地狱)。
Also, if you have a 64 bit EXE, you will have to check for both, the 32 AND 64 bit runtimes.
Function TryLaunchApplication
Pop $1 ; pathname
nsExec::Exec $1
Pop $0
${If} $0 == "error"
${OrIf} $0 != 0
Push 0
${Else}
Push 1
${EndIf}
FunctionEnd
并在函数中调用它,例如 CheckRuntimes
Function CheckRuntimes
; Try to execute VC++ 10 application (32 bit)
Push "Vc10RuntimeCheckerApp.exe"
Call TryLaunchApplication
Pop $Vc10RuntimesFound
; Add 64 bit check if required.
; Remember to try running the 64 bit EXE only on a 64 bit OS,
; which requires further checks.
; Try to execute .net application
Push "DotNetRuntimeCheckerApp.exe"
Call TryLaunchApplication
Pop $DotNetFrameworkFound
FunctionEnd
Then launch the runtime check e.g. when leaving the 欢迎光临 page and cache the result, so you don't have to re-check every time the user clicks on the "Back" and "Next" button.
Old question but here is the approach we have used ever since Visual Studio 2005 with success. I just tested it using Visual Studio 2012 Update 4 as well (since we are finally updating our software from 2010 to 2012).
由于 Visual C + + 可再发行包在 Windows 中注册了它们的卸载程序(因此它显示在控制面板的“程序和特性”列表中) ,我们只需检查注册表中卸载程序键的显示名称。
以下是相关的 NSIS 代码:
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}\" "DisplayName"
StrCmp $0 "Microsoft Visual C++ 2012 Redistributable (x86) - 11.0.61030" vs2012redistInstalled
DetailPrint "Microsoft Visual C++ 2012 Update 4 Redistributable not found!"
DetailPrint "Downloading from www.mywebsite.com"
; insert applicable download code here
ExecWait '"<downloaded redist exe>" /promptrestart /passive'
vs2012redistInstalled:
Note that since our installer is a 32bit exe, windows handles determining if the registry key is actually in the virtualized Wow6432Node instead of the above location so the above code works on both 64bit and 32bit windows installs without having to check both keys explicitly.
Microsoft Visual C++ 2005 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\c1c4f01781cc94c4c8fb1542c0981a2a
Configuration: x86
Version: 6.0.2900.2180
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161 (SP1)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\6E815EB96CCE9A53884E7857C57002F0
Configuration: x86
Version: 9.0.30729.6161 (Actual $Version data in registry: 0x9007809 [DWORD])
Microsoft Visual C++ 2010 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1D5E3C0FEDA1E123187686FED06E995A
Configuration: x86
Version: 10.0.40219.325
Microsoft Visual C++ 2012 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}
Configuration: x86
Version: 11.0.61030.0
Microsoft Visual C++ 2013 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{f65db027-aff3-4070-886a-0d87064aabb1}
Configuration: x86
Version: 12.0.30501.0
Microsoft Visual C++ 2015 Redistributable (x86) - 14.0.24215
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{e2803110-78b3-4664-a479-3611a381656a}
Configuration: x86
Version: 14.0.24215.1
Microsoft Visual C++ 2017 Redistributable (x86) - 14.16.27012
Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\VC,redist.x86,x86,14.16,bundle\Dependents\{67f67547-9693-4937-aa13-56e296bd40f6}]
Configuration: x86
Version: 14.16.27012.6
Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.21.27702
Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\VC,redist.x86,x86,14.21,bundle\Dependents\{49697869-be8e-427d-81a0-c334d1d14950}]
Configuration: x86
Version: 14.21.27702
Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.22.27821
Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\VC,redist.x86,x86,14.22,bundle\Dependents\{5bfc1380-fd35-4b85-9715-7351535d077e}]
Configuration: x86
Version: 14.22.27821
Checking the install state for the product via MsiQueryProductState is pretty much equivalent to checking the registry directly, but you still need the GUID for the ProductCode 产品代码.
@ECHO OFF
:Author
REM "CREATED BY WAR59312"
REM "FEB 7th 2017"
REM Clear Screen
CLS
TITLE Detect Visual C++ 2012 Redistributables
REM This Batch Script Detects If Visual C++ Redistributable for Visual Studio 2012 Update 4 Is Installed
:DetectWindowsOS
REM Are We Running On x86 Or x64
IF NOT DEFINED PROCESSOR_ARCHITEW6432 (
IF %PROCESSOR_ARCHITECTURE% EQU x86 (
REM Windows Is x86
GoTo Check32Bit
) ELSE (
REM Windows Is x64
SET NeededFor64BitOnly=/reg:32
GoTo Check64Bit
)) ELSE (
REM Windows Is Unknown But Assume x64 To Be Safe
SET NeededFor64BitOnly=/reg:32
GoTo Check64Bit
)
:Check64Bit
REM Checks If Visual C++ 64Bit Redistributable for Visual Studio 2012 Update 4 Is Installed
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes\x64" /v "Version" %NeededFor64BitOnly% 2>NUL^ | (
FIND "v11.0.61030.00" >NUL
) && (
ECHO.
ECHO 64bit Visual C++ Redistributable for Visual Studio 2012 Update 4 Is Installed
ECHO.
GoTo Check32Bit
) || (
ECHO.
ECHO 64bit Visual C++ Redistributable for Visual Studio 2012 Update 4 Is NOT Installed
ECHO.
GoTo Check32Bit
)
:Check32Bit
REM Checks If Visual C++ 32Bit Redistributable for Visual Studio 2012 Update 4 Is Installed
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes\x86" /v "Version" %NeededFor64BitOnly% 2>NUL^ | (
FIND "v11.0.61030.00" >NUL
) && (
ECHO.
ECHO 32bit Visual C++ Redistributable for Visual Studio 2012 Update 4 Is Installed
) || (
ECHO.
ECHO 32bit Visual C++ Redistributable for Visual Studio 2012 Update 4 Is NOT Installed
)
:END
ECHO.
PAUSE
EXIT
我碰巧遇到这个问题,在检查由 WiX 创建的 MSI 安装程序中的 Visual C + + 可再发行部分的上下文中寻找答案。
我不喜欢 GUID 在版本和操作系统上的改变,所以我最终创建了一个用 C # 编写的自定义操作来检查 Visual C + + 的可再发行性。
下面的所有内容都是专门针对 Visual C + + 2015可再发行版(x64)的,但是可以很容易地对任何版本进行修改。
using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;
namespace CustomActions
{
public class DependencyChecks
{
[CustomAction]
public static ActionResult IsVC2015RedistInstalled(Session session)
{
session.Log("Begin Visual C++ 2015 Redistributable installation check.");
var dependenciesKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\Installer\\Dependencies");
foreach(var subKey in dependenciesKey.GetSubKeyNames())
{
var dependency = dependenciesKey.OpenSubKey(subKey);
var displayName = (string)dependency.GetValue("DisplayName");
if(displayName != null)
{
if (displayName.Contains("Microsoft Visual C++ 2015 Redistributable (x64)"))
{
session.Log("Visual C++ 2015 Redistributable is installed.");
return ActionResult.Success;
}
}
}
session.Log("Visual C++ 2015 Redistributable is not installed.");
session.Message(InstallMessage.Error, new Record(1, "This application requires Visual C++ 2015 Redistributable. Please install, then run this installer again. https://www.microsoft.com/en-us/download/details.aspx?id=53587"));
return ActionResult.Failure;
}
}
}
I have created a powershell script that checks and installs the versions the user specifies, i haven't done extensive testing with it, but for my own CI (Continuous Integration) scenario it work perfectly.