检测是否安装了Visual Studio 2012的Visual C ++ Redistributable

如何检测Visual Studio 2012的Visual C ++ Redistributable是否安装?

我试了Google,没有人问这个问题,惊喜!

这取决于你使用的是什么版本。 这两个2012键对我来说效果不错,他们的相应版本可以下载更新4.请注意,这些注册地址中的一些可能取决于操作系统。 我从Windows 10 x64框中收集了这些信息。 我只是要继续前进,转储所有这些redist版本和我search的registry键来检测安装情况。


Visual C ++ 2005

Microsoft Visual C++ 2005 Redistributable (x64) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1af2a8da7e60d0b429d7e6453b3d0182 Configuration: x64 Version: 6.0.2900.2180 

直接下载URL: https : //download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE

 Microsoft Visual C++ 2005 Redistributable (x86) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\c1c4f01781cc94c4c8fb1542c0981a2a Configuration: x86 Version: 6.0.2900.2180 

直接下载url: https : //download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE


Visual C ++ 2008

 Microsoft Visual C++ 2008 Redistributable (x64) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\67D6ECF5CD5FBA732B8B22BAC8DE1B4D Configuration: x64 Version: 9.0.30729.5677 

直接下载url: https : //download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe

 Microsoft Visual C++ 2008 Redistributable (x86) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\6E815EB96CCE9A53884E7857C57002F0 Configuration: x86 Version: 9.0.30729.5677 

直接下载url: https : //download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x86.exe


Visual C ++ 2010

 Microsoft Visual C++ 2010 Redistributable (x64) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1926E8D15D0BCE53481466615F760A7F Configuration: x64 Version: 10.0.40219.325 

直接下载url: https : //download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe

 Microsoft Visual C++ 2010 Redistributable (x86) Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1D5E3C0FEDA1E123187686FED06E995A Configuration: x86 Version: 10.0.40219.325 

直接下载url: https : //download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe


Visual C ++ 2012

 Microsoft Visual C++ 2012 Redistributable (x64) Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6} Configuration: x64 Version: 11.0.61030.0 

直接下载url: https : //download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe

 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 

直接下载url: https : //download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe


Visual C ++ 2013

 Microsoft Visual C++ 2013 Redistributable (x64) Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{050d4fc8-5d48-4b8f-8972-47c82c46020f} Configuration: x64 Version: 12.0.30501.0 

直接下载url: https : //download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe

 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 

直接下载url: https : //download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe


Visual C ++ 2015

 Microsoft Visual C++ 2015 Redistributable (x64) - 14.0.24215 Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{d992c12e-cab2-426f-bde3-fb8c53950b0d} Configuration: x64 Version: 14.0.24215.1 

直接下载url: https : //download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe

 Microsoft Visual C++ 2015 Redistributable (x86) - 14.0.24215 Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{e2803110-78b3-4664-a479-3611a381656a} Configuration: x86 Version: 14.0.24215.1 

直接下载url: https : //download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x86.exe


Visual C ++ 2017

警告 :有一个新的2017年注册公约正在使用,或者还没有最终确定。 正如我猜测最上面的键: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,amd64,14.0,bundle][HKEY_CLASSES_ROOT\Installer\Dependencies\,,x86,14.0,bundle]

是可以改变的,或者至less有不同的嵌套的GUID,我将使用列出以GUID结尾的键。

 Microsoft Visual C++ 2017 Redistributable (x64) - 14.11.25325 Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,amd64,14.0,bundle\Dependents\{6c6356fe-cbfa-4944-9bed-a9e99f45cb7a}] Configuration: x64 Version: 14.11.25325.0 

直接下载url: https : //download.visualstudio.microsoft.com/download/pr/11100230/15ccb3f02745c7b206ad10373cbca89b/VC_redist.x64.exe

 Microsoft Visual C++ 2017 Redistributable (x86) - 14.11.25325 Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,x86,14.0,bundle\Dependents\{404c9c27-8377-4fd1-b607-7ca635db4e49}] Configuration: x86 Version: 14.11.25325.0 

直接下载url: https : //download.visualstudio.microsoft.com/download/pr/11100229/78c1e864d806e36f6035d80a0e80399e/VC_redist.x86.exe


更新日志
2017年9月8日 – 新增Visual C ++ 2017条目,新增2017版本14.11.25325.0
2017年4月7日 – 添加了2017年版本的14.10.25008.0作为新的Visual C ++ 2017条目
2016年10月24日 – 更新了2015年的版本信息14.0.24215.1
2016年8月18日 – 更新了2015年14.0.24212的版本信息
2016年5月27日 – 更新信息MSVC2015更新2

如果其中任何一个过时,请与我联系。

尝试

 HKLM\SOFTWARE\Microsoft\DevDiv\VC\Servicing\11.0 

作为一个起点。 我将用它来检查安装VC ++ 11(VS 2012)的运行时间。

您可以在64位系统上的以下registry位置检查Installed值为1HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\VC\Runtimes\x86 。 在代码将导致访问registry项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes\x86 。 注意Wow6432Node的缺席。

在32位系统上registry是相同的没有Wow6432NodeHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes\x86

Visual C ++附带的引导程序包清单中没有installcheck元素。 猜猜如果您将其设置为先决条件,Microsoft希望始终进行安装。

当然,您仍然可以调用MsiQueryProductState来检查是否通过MSI安装了VC redist包,可以通过运行

 wmic product get 

在命令行,或者如果你已经在wmic:root \ cli,运行

 product where "Caption like '%C++ 2012%'" 

由于Visual Studio 2010和更高版本停止使用WinSxS,因此检查%windir%\ system32 \ msvcr110.dll可能就足够了。 如果要validation是否有足够新的版本,可以检查文件版本是11.0.50727.1(VS2012 RTM)还是11.0.51106.1(VS2012 Update 1)。

不幸的是,这个简单问题的答案不是一个简单的问题,而是在100%的系统中工作,甚至可以扩展到众多的.net框架。

复杂性来自事实上有许多VC运行时版本可能会导致这样的情况,即虽然安装了VC10运行时,但是它们的版本号还不够新,所以如果你没有安装你需要的确切的运行时间,或者使得这个版本和以前的版本能够在同一主版本上运行的更新运行时间(并排地狱)。 此外,如果你有一个64位的EXE,你将不得不检查32和64位运行时。

也就是说,确定EXE的运行时是否安装的唯一可靠方法是尝试运行EXE ,或者使用与主EXE相同的设置构build的另一个EXE,其唯一目的是为了执行任何操作。 只是运行(这意味着运行时已安装)或无法运行(未安装时)。

我为需要安装VC10 32和64位运行时的安装程序执行以下操作:安装程序尝试启动所有虚拟EXE,如果成功,则认为已安装相应的运行时。 这也解决了32/64位的情况。

顺便说一下,这也可以确定是否安装了正确的.net框架,这在Windows 8和Windows 10中是非常棘手的,因为可下载的内置.net 3.5支持也支持.net版本3.0和2.0。没有这些registry项。 (更糟的是,你甚至不能在这里使用标准的框架安装程序,你必须使用内置的支持,并通过Windows下载,或使用.net 4重build你的应用程序,但这是另一回事)。

可以使用具有以下代码的项目来构buildC ++ dummy EXE(如果需要,还可以使用64位configuration中的另一个):

 int _tmain(int argc, _TCHAR* argv[]) { return 0; } 

请记住设置项目的属性使用MFC在共享DLL中使用MFC 。 可执行文件的大小约为4KB,这是一个确定的结果。

为了给用户一个很好的安装经验,你可以做下面的事情(示例代码是NSIS ):

 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 

然后启动运行时检查,例如,离开欢迎页面并caching结果时,不必每次用户点击“后退”和“下一步”button时重新检查。

接下来,在安装树中创build一个只读部分,并在显示“ 组件”页面之前执行的function中预先select或取消select该部分

这将确保每个缺less的运行时组件的安装是必需的,并且如果它已经存在则被跳过。

对我来说,这个位置工作:HKEY_LOCAL_MACHINE \ SOFTWARE \微软\ DevDiv \ VC \服务\ 11.0 \ RuntimeMinimum \版本

安装软件包后,请检查您的版本,并将其用作安装程序的条件。 (安装VCred后我的设置为11.0.50727)。

 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 

只要去控制面板>程序和function,他们都出现在那里。

我不是专家,这个答案与人们正在回答的问题(检查registry)相比是非常简单的,所以我不确定这是否是正确的答案,但是对我来说这是个窍门。

程序和特点

我已经成功地用InnoSetup做这个。

我检查了registry项的存在:

HKLM\SOFTWARE\Microsoft\VisualStudio\11.0\VC\Runtimes

如果卸载,它不存在。 如果安装,它存在。

顺便说一下,它也可以在Wow6432Node中:

HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\VC\Runtimes

通过MsiQueryProductState检查产品的安装状态与直接检查registry非常相似,但仍需要ProductCode的GUID。

如别处所述,这些方法的一个缺点是每个更新都有自己的ProductCode!

值得庆幸的是,MSI提供了一个标识产品“家族”的升级代码 。 您可以使用orca打开其中一个MSI来提取此信息。 例如,VS2015可再发行版的UpgradeCode是{65E5BD06-6392-3027-8C26-853107D3CF1A}

您可以使用MsiEnumRelatedProducts获取该UpgradeCode的所有产品ID。 实际上,由于每个redist更新取代了前一个,所以这只会产生一个ProductCode – 例如VS2015 Update 2 x86的{B5FC62F5-A367-37A5-9FD2-A6E137C0096F}

无论如何,您可以通过MsiGetProductInfo (productCode,INSTALLPROPERTY_VERSIONSTRING,…)或类似的函数来检查版本,以便与您想要的版本进行比较,例如检查等效版本或更高版本。

请注意,在C ++应用程序中,如果您使用#include <crtversion.h> ,则还可以使用_VC_CRT_MAJOR_VERSION_VC_CRT_MINOR_VERSION_VC_CRT_BUILD_VERSION – 这样您可以确定计算二进制文件的CRT版本。

这个PowerShell的代码应该做的伎俩

 Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize 

我需要同样的东西,虽然AFAIK不能以编程的方式完成,但它对我有效。

我只是去开始 – “卸载程序,并向下滚动,直到我find了VC ++可再发行,其中包括一个版本号。 使用谷歌search的版本号,告诉我它属于VS2012 SP1。

老问题,但这里是从Visual Studio 2005成功以来我们使用的方法。 我刚刚使用Visual Studio 2012 Update 4进行了testing(因为我们正在从2010年到2012年更新我们的软件)。

由于Visual C ++可重新分发程序包使用Windows注册其卸载程序(因此它显示在控制面板的“程序和function”列表中),我们只需在registry中检查卸载程序键的显示名称即可。

这里是相关的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: 

请注意,由于我们的安装程序是一个32位的exe文件,因此windows会处理确定registry项是否实际位于虚拟化的Wow6432Node中,而不是上述位置,所以上述代码可以在64位和32位Windows上安装,而无需明确检查两个键。

另外请注意,要将上面的代码更新到不同版本的VC ++ Redist,只需将registry项path中的GUID和显示名称更改为所需的任何内容即可。

虽然这可能不是推荐的方法,但是在过去的10年中,它已经在超过10万台机器上运行,从2005年,2010年,2010年1月1日和现在的2012年4月,使用redist来运行XP / XP64的各种Windows。

我会检查的Installed

HKLM\SOFTWARE\[WOW6432Node]\Microsoft\Windows\CurrentVersion\Uninstall\{VCRedist_GUID}

  • 其中VC++ 2012 (x86) GUID为{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}
  • WOW6432Node将存在与否取决于VC++ redist产品

大多数人错过的是所需的/reg:32来检查Windows x64上的密钥。

请参阅有关此主题的Microsoft帮助文章 。

以下是演示如何正确检查Visual Studio 2012更新4的Visual C ++ Redistributable的脚本。

 @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 

我碰到这个问题,在检查Visual C ++可再发行组件作为由WiX创build的MSI安装程序的一部分的上下文中寻找答案。

我不喜欢如何在版本和操作系统的GUID的变化,所以我最终创build了一个用C#编写的自定义操作来检查Visual C ++可再发行。

下面的所有内容专门针对Visual C ++ 2015 Redistributable(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; } } } 

然后在wxs文件中

 <Binary Id='VC2015RedistCheck' SourceFile='!(wix.ResourcesDir=resources)\CustomActions.CA.dll'/> <CustomAction Id='VC2015RedistCheckAction' Execute='immediate' BinaryKey='VC2015RedistCheck' DllEntry="IsVC2015RedistInstalled" Return='check'/> <InstallExecuteSequence> <Custom Action='VC2015RedistCheckAction' After='InstallInitialize'/> </InstallExecuteSequence> 

你可以在registry中search。实际上我没有vs2012,但我有vs2010。

有3个不同(但非常相似)的registry键为3个平台包中的每一个。 每个键都有一个名为“Installed”的DWORD值,值为1。

  • HKLM \ SOFTWARE \微软\ VisualStudio的\ 10.0 \ VC \ VCRedist \ X86

  • HKLM \ SOFTWARE \微软\ VisualStudio的\ 10.0 \ VC \ VCRedist \ 64

  • HKLM \ SOFTWARE \微软\ VisualStudio的\ 10.0 \ VC \ VCRedist \ IA64

你可以使用registryfunction……