C# detect latest .net framework installed on PC
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的更多相关文章
- 判断 .NET Framework安装版本
How To Determine the .NET Framework Installed Versions This topic is a how to.Please keep it as clea ...
- CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法
今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net Framework Data Provider 可能没有安装. 下面找到官方的文档说明: SQLi ...
- CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]
原文:http://www.cnblogs.com/chenrui7/p/3592082.html 今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net ...
- .NET Framework 类库
.NET Framework 类库 MSDN == V2.0 == .NET Framework 类库是一个由 Microsoft .NET Framework SDK 中包含的类.接口和值类型组成的 ...
- Hyper-V和Virtual PC的不同
微软在2003年收购了推出了Virtual PC软件的Connectix公司,并在其后推出了Virtual Server服务器虚拟化软件 Hyper-V跟微软自家的Virtual PC.Virtual ...
- Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 38 Entity Framework ...
- 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 ...
- QUICK START GUIDE
QUICK START GUIDE This page is a guide aimed at helping anyone set up a cheap radio scanner based on ...
- Configuring and troubleshooting a Schema Provider
原文:https://codesmith.atlassian.net/wiki/display/Generator/Configuring+and+troubleshooting+a+Schema+P ...
随机推荐
- 《Java数据结构》链表结构(单向链表,双向链表)
单向链表(单链表)是链表的一种,其特点是链表的链接方向是单向的,对链表的访问要通过顺序读取从头部开始:链表是使用指针进行构造的列表:又称为结点列表,因为链表是由一个个结点组装起来的:其中每个结点都有指 ...
- df,dh 命令
原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/df2f05c4-b ...
- SpringBoot微服务电商项目开发实战 --- 模块版本号统一管理及Redis集成实现
上一篇文章总结了基于SpringBoot实现分布式微服务下的统一配置.分环境部署配置.以及服务端模块的分离(每一个提供者就是一个独立的微服务).微服务落地.Dubbo整合及提供者.消费者的配置实现.本 ...
- Odoo系统有哪些不同版本?
来源:www.odooyun.com 1. Odoo10.0 vs Odoo11.0 vs 8.0 截至2017年底,最新的Odoo发布版为Odoo 11.0,但功能上有一定精简(去除财务模块,去除工 ...
- 集合系列 Map(十四):WeakedHashMap
WeakedHashMap 也是 Map 集合的哈希实现,但其余 HashMap 的不同之处在于.其每个节点的 value 引用是弱引用,可以方便 GC 回收. public class WeakHa ...
- python3抓取淘宝评论内容
好久没有写爬虫了,今天研究了下淘宝商品评论的内容. 一开始用最简单的方法,挂代理,加请求头,对网页请求,是抓不到数据的,在网上找了一些相关文章,也基本已经过时了,就是网站逻辑有改动,用旧的方法是抓不到 ...
- jQuery随笔记录
DOM遍历 parent()方法返回所选元素的直接父元素.(parent() 只能遍历单个级别的 DOM树) parents()方法获取所选元素的所有祖先 children()所选元素 ...
- JS---part2课程介绍+part1复习
part1复习 JavaScript分三个部分: 1. ECMAScript标准----JS基本的语法 2. DOM:Document Object Model 文档对象模型 3. BOM:浏览器对象 ...
- 部署vue-element-admin流程
1.修改环境变量: 在以下两个文件: .env_staging [如果修改这个,需要以npm run build:stage启动] .env_production [如果修改这个,需要以npm run ...
- BlockStack常见词语
Browser: 用户用来浏览并使用基于 blockstack 网络开发的 app. CLI: Cli 工具用来管理个人的 blockstack id. blockstack.js (and othe ...