c# - 如何检查设备上是否安装了 Microsoft Visual C++ 2015 Redistributable
问题描述
正如标题所说,我目前找不到这个问题的任何答案。
我目前正在使用 C# 进行检查。
大多数答案适用于 2013 版及以下版本。
如果大家有什么建议,请分享。
谢谢。
解决方案
很难获得 VC 2015 的所有注册表值,所以我编写了一个小函数,它将遍历所有依赖项并匹配指定版本(C++ 2015 x86)
public static bool IsVC2015x86Installed()
{
string dependenciesPath = @"SOFTWARE\Classes\Installer\Dependencies";
using (RegistryKey dependencies = Registry.LocalMachine.OpenSubKey(dependenciesPath))
{
if (dependencies == null) return false;
foreach (string subKeyName in dependencies.GetSubKeyNames().Where(n => !n.ToLower().Contains("dotnet") && !n.ToLower().Contains("microsoft")))
{
using (RegistryKey subDir = Registry.LocalMachine.OpenSubKey(dependenciesPath + "\\" + subKeyName))
{
var value = subDir.GetValue("DisplayName")?.ToString() ?? null;
if (string.IsNullOrEmpty(value)) continue;
if (Regex.IsMatch(value, @"C\+\+ 2015.*\(x86\)")) //here u can specify your version.
{
return true;
}
}
}
}
return false;
}
依赖项:
using System;
using System.Text.RegularExpressions;
using Microsoft.Win32;
编辑:
C++ 2017 是 C++ 2015 的有效替代品,因此如果您还想检查它,请像这样编辑正则表达式:
Regex.IsMatch(value, @"C\+\+ (2015|2017).*\(x86\)")
推荐阅读
- kubernetes - 无法附加或挂载卷:未挂载的卷
- node.js - 像“ORDER BY”和“GROUP BY”这样的子句是否容易在 SQLite 中注入?
- html - 如何将导航栏置于屏幕中央?
- pdf - How to convert multiple markdown docs with links between them into one pdf?
- azure - Azure 通信服务上的入站呼叫
- regex - 我有一个 Jinja 模板,它只打印正则表达式匹配的第一个匹配,但我希望它打印所有匹配
- python - 如何根据另一列的两个连续值在熊猫的新列中添加标签?
- javascript - 如何在反应钩子中使用复选框过滤获取的数据
- python - 如何将多个分类列转换为在 PySpark 中保持共享值的整数?
- android - 如何在底部导航栏添加一行