-
C#教程之C# detect latest .net framework installed on PC
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
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=="1") { 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=="1") { Console.WriteLine($"{subKeyName} {name} SP{sp}"); } else if(install=="1") { 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>=528040) { return "4.8 or later"; } if(releaseKey>=461808) { return "4.7.2"; } if(releaseKey>=461308) { return "4.7.1"; } if (releaseKey >= 460798) { return "4.7"; } if(releaseKey>=394802) { return "4.6.2"; } if(releaseKey>=394254) { return "4.6.1"; } if(releaseKey>=393295) { return "4.6"; } if(releaseKey>=393295) { return "4.5.2"; } if(releaseKey>=378675) { return "4.5.1"; } if(releaseKey>=378389) { return "4.5"; } return "No 4.5 or later version detected!"; }
栏目列表
最新更新
动手造轮子:实现一个简单的依赖注入
C# detect latest .net framework installed on PC
浅谈.NET中的反射
C#面向对象--命名空间
6. abp中的拦截器
Winform中在使用VS+svn进行协同开发时添加引
Cef 因系统时间不正常,导致页面访问空白
C# copy files from source directory to destination
在代码生成工具Database2Sharp中使用ODP.NET(
C#如何判断委托是实例方法还是静态方法
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能
将Session值储存于SQL Server中
使用SQL Server数据库嵌套子查询的方法
SQL概述