检测 .net framework 4.5.X 是否安装在 OS 中?
Detect if .net framework 4.5.X is installed in OS?
我需要检测当前 OS 上是否安装了 .net framework 4.5.X?
我尝试了 this 但似乎仅限于使用非官方更新的框架 4.0。
刚刚为您进行了谷歌搜索,发现以下 MSDN 文章直接引用了您的问题。包括 4.5 版及更高版本的示例...
https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
您可以查看注册表或直接查看已安装的程序。
在“开始”菜单中键入 "appwiz.cpl",然后搜索 .net
您将看到所有安装在您机器上的 .net。
// Checking the version using >= will enable forward compatibility,
// however you should always compile your code on newer versions of
// the framework to ensure your app works the same.
private static string CheckFor45DotVersion(int releaseKey)
{
if (releaseKey >= 393295) {
return "4.6 or later";
}
if ((releaseKey >= 379893)) {
return "4.5.2 or later";
}
if ((releaseKey >= 378675)) {
return "4.5.1 or later";
}
if ((releaseKey >= 378389)) {
return "4.5 or later";
}
// This line should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
private static void Get45or451FromRegistry()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")) {
if (ndpKey != null && ndpKey.GetValue("Release") != null) {
Console.WriteLine("Version: " + CheckFor45DotVersion((int) ndpKey.GetValue("Release")));
}
else {
Console.WriteLine("Version 4.5 or later is not detected.");
}
}
}
我需要检测当前 OS 上是否安装了 .net framework 4.5.X?
我尝试了 this 但似乎仅限于使用非官方更新的框架 4.0。
刚刚为您进行了谷歌搜索,发现以下 MSDN 文章直接引用了您的问题。包括 4.5 版及更高版本的示例...
https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
您可以查看注册表或直接查看已安装的程序。 在“开始”菜单中键入 "appwiz.cpl",然后搜索 .net 您将看到所有安装在您机器上的 .net。
// Checking the version using >= will enable forward compatibility,
// however you should always compile your code on newer versions of
// the framework to ensure your app works the same.
private static string CheckFor45DotVersion(int releaseKey)
{
if (releaseKey >= 393295) {
return "4.6 or later";
}
if ((releaseKey >= 379893)) {
return "4.5.2 or later";
}
if ((releaseKey >= 378675)) {
return "4.5.1 or later";
}
if ((releaseKey >= 378389)) {
return "4.5 or later";
}
// This line should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
private static void Get45or451FromRegistry()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")) {
if (ndpKey != null && ndpKey.GetValue("Release") != null) {
Console.WriteLine("Version: " + CheckFor45DotVersion((int) ndpKey.GetValue("Release")));
}
else {
Console.WriteLine("Version 4.5 or later is not detected.");
}
}
}