以VC++ 2013为例
using Microsoft.Win32;
using System;
using System.Diagnostics;
namespace Test
{
class Program
{
static void Main(string[] args)
{
var vc2013Name = @"Microsoft Visual C++ 2013 Redistributable (x86)";
var version = IsInstalledFromRegistry(vc2013Name);
Debug.WriteLine(version.ToString());
}
public static bool IsInstalledFromRegistry(string displayName)
{
var registryPath = @"SOFTWAREWOW6432NodeMicrosoftWindowsCurrentVersionUninstall";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryPath, false))
{
foreach (var keyName in key.GetSubKeyNames())
{
if (string.IsNullOrEmpty(keyName))
{
continue;
}
using (var subKey = key.OpenSubKey(keyName, false))
{
if (subKey == null)
{
continue;
}
var name = subKey.GetValue("DisplayName");
if (name != null && name.ToString().StartsWith(displayName))
{
return true;
}
}
}
}
return false;
}
}
}