static void GetNetVersionDemo()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
foreach(var versionKeyName in ndpKey.GetSubKeyNames())
{
//Skip .NET Framework 4.5 version information.
if(versionKeyName=="v4")
{
continue;
} if(versionKeyName.StartsWith("v"))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); //Get the .NET Framework version value.
var name = (string)versionKey.GetValue("Version", ""); //Get the service pack number.
var sp = versionKey.GetValue("SP", "").ToString(); //Get the installation flag,or an empty string if there is none.
var install = versionKey.GetValue("Install", "").ToString(); if(string.IsNullOrEmpty(install))
{
Console.WriteLine($"{versionKeyName} {name}");
}
else
{
if(!string.IsNullOrEmpty(sp) && install=="")
{
Console.WriteLine($"{versionKeyName} {name} SP{sp}");
}
} if(!string.IsNullOrEmpty(name))
{
continue;
} foreach(var subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", "");
if(!string.IsNullOrEmpty(name))
{
sp = subKey.GetValue("SP", "").ToString();
} install = subKey.GetValue("Install", "").ToString();
if(string.IsNullOrEmpty(install))
{
Console.WriteLine($"{versionKeyName} {name}");
}
else
{
if((!string.IsNullOrEmpty(sp)) && install=="")
{
Console.WriteLine($"{subKeyName} {name} SP{sp}");
}
else
if(install=="")
{
Console.WriteLine($"{subKeyName} {name}");
}
}
}
}
}
}
}

using Microsoft.Win32;

static void Main(string[] args)
{
GetDotNetFrameworkVersion();
Console.ReadLine();
} static void GetDotNetFrameworkVersion()
{
const string subKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full";
using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subKey))
{
if(ndpKey!=null && ndpKey.GetValue("Release")!=null)
{
var objResult = ndpKey.GetValue("Release");
var versionResult = CheckFor45PlusVersion((int)objResult);
Console.WriteLine($".NET Framework Version:{versionResult}");
}
else
{
Console.WriteLine(".NET Framework Version 4.5 or later is not detected!");
}
}
} //Convert the Main.Minor.Build.Revision
static string CheckFor45PlusVersion(int releaseKey)
{
if(releaseKey>=)
{
return "4.8 or later";
} if(releaseKey>=)
{
return "4.7.2";
} if(releaseKey>=)
{
return "4.7.1";
} if (releaseKey >= )
{
return "4.7";
} if(releaseKey>=)
{
return "4.6.2";
} if(releaseKey>=)
{
return "4.6.1";
} if(releaseKey>=)
{
return "4.6";
} if(releaseKey>=)
{
return "4.5.2";
} if(releaseKey>=)
{
return "4.5.1";
} if(releaseKey>=)
{
return "4.5";
} return "No 4.5 or later version detected!";
}

C# detect latest .net framework installed on PC的更多相关文章

  1. 判断 .NET Framework安装版本

    How To Determine the .NET Framework Installed Versions This topic is a how to.Please keep it as clea ...

  2. CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法

    今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net Framework Data Provider 可能没有安装. 下面找到官方的文档说明: SQLi ...

  3. CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]

    原文:http://www.cnblogs.com/chenrui7/p/3592082.html 今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net ...

  4. .NET Framework 类库

    .NET Framework 类库 MSDN == V2.0 == .NET Framework 类库是一个由 Microsoft .NET Framework SDK 中包含的类.接口和值类型组成的 ...

  5. Hyper-V和Virtual PC的不同

    微软在2003年收购了推出了Virtual PC软件的Connectix公司,并在其后推出了Virtual Server服务器虚拟化软件 Hyper-V跟微软自家的Virtual PC.Virtual ...

  6. Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core

    本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 38 Entity Framework ...

  7. Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity Framework Core

    本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity F ...

  8. QUICK START GUIDE

    QUICK START GUIDE This page is a guide aimed at helping anyone set up a cheap radio scanner based on ...

  9. Configuring and troubleshooting a Schema Provider

    原文:https://codesmith.atlassian.net/wiki/display/Generator/Configuring+and+troubleshooting+a+Schema+P ...

随机推荐

  1. 【转载】[C++ STL] deque使用详解

    转载自 https://www.cnblogs.com/linuxAndMcu/p/10260124.html 一.概述 deque(双端队列)是由一段一段的定量连续空间构成,可以向两端发展,因此不论 ...

  2. Android WebView 加载富文本内容

    WebView加载数据的方式有两种: 1. webView.loadUrl(data);//加载url 2. webView.loadDataWithBaseURL(null,data, " ...

  3. Bash脚本编程之算术运算

    简介 Bash所支持的算术运算和C语言是一样的,这里指的是操作符(operator)以及它们的优先级(precedence).结合性(associativity)和值,详见Shell Arithmet ...

  4. 好用的Markdown编辑器安利-Typora

    Typora,一款还用极简优秀的免费开源Markdown编辑器,非常值得每一位爱好Markdown的朋友学习和使用.我个人是深深被它吸引了,不论是写博客还是记笔记,Typora都是我十足的好帮手.Ty ...

  5. vue中实现百度地图

    1.项目根目录下下载百度地图插件 npm install vue-baidu-map –save 2.在首页index.html中引入百度地图: <script type="text/ ...

  6. 一个经典的代码--Convert char to int in C and C++

    前记 写程序,就像建房子,对于高超的建筑师来说,是要有一些好的素材的.作为一个程序员,见了好用的素材存起来,以备后面需要,也是一门很好的修养. 实例代码 一个char 转int的经典代码,这里分享一下 ...

  7. IT兄弟连 HTML5教程 CSS3属性特效 transition过渡

    CSS3的transition允许css的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值. transitio ...

  8. 使用redisson时关于订阅数的问题

    在使用redisson消息订阅时,我针对门店商品库存减扣进行订阅的操作(在这里一个商品一个监听队列),当正式投入生产时,发现一直再报Subscribe timeout: (" + timeo ...

  9. SpringCloud之Feign 负载均衡请求超时时间

    版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,那 ...

  10. (转)Python中的常见特殊方法—— repr方法

    原文链接:https://www.cnblogs.com/tizer/p/11178473.html 在Python中有些方法名.属性名的前后都添加了双下划线,这种方法.属性通常都属于Python的特 ...