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. 创建基于ASP.NET core 3.1 的RazorPagesMovie项目(一)-创建和使用默认的模板

    声明:参考于asp.net core 3.1 官网(以后不再说明) 本教程是系列教程中的第一个教程,介绍生成 ASP.NET Core Razor Pages Web 应用的基础知识. 在本系列结束时 ...

  2. 动态代理模式_应用(Redis工具类)

    本次使用动态代理的初衷是学习Redis,使用Java操作Redis时用到Jedis的JedisPool,而后对Jedis的方法进一步封装完善成为一个工具类.因为直接使用Jedis对象时,为了保证性能, ...

  3. Android判断com.android.camera.action.CROP是否存在

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/225 最近线上报错,有个用户连续crash了10次左右,查 ...

  4. 微服务与敏捷开发(Scrum/Kanban)的核心思想之我见

    微服务与敏捷开发(Scrum/Kanban)的核心思想之我见   关于"微服务"和"敏捷开发"的文章网络上有很多,所以这里不再重复叙述这些概念的解释和特点,而是 ...

  5. zabbix服务深入

    第1章 Grafana自定义图形 1.安装grafana [root@m01 /data/soft]# wget https://dl.grafana.com/oss/release/grafana- ...

  6. Asp.Net MVC Webapi Eventsource 实现时效消息

    ApiController 后端API public System.Net.Http.HttpResponseMessage GetUnknownNotices() { var user = Form ...

  7. 源码角度分析-newFixedThreadPool线程池导致的内存飙升问题

    前言 使用无界队列的线程池会导致内存飙升吗?面试官经常会问这个问题,本文将基于源码,去分析newFixedThreadPool线程池导致的内存飙升问题,希望能加深大家的理解. (想自学习编程的小伙伴请 ...

  8. IPFS学习-分布式哈希表DHT

    Distributed Hash Tables(DHT) 分布式哈希表是一个分布式的键值对存储结构.在IPFS网络中,每一个节点都维护一个DHT的子集.当节点接受到一个请求.该节点要么直接回复,要么通 ...

  9. alpine制作jdk、jre镜像、自定义镜像上传阿里云

    alpine制作jdk镜像 alpine Linux简介 1.Alpine Linux是一个轻型Linux发行版,它不同于通常的Linux发行版,Alpine采用了musl libc 和 BusyBo ...

  10. JavaWeb入门——在Windows环境下安装Tomcat服务器

    JavaWeb入门——在Windows环境下安装Tomcat服务器 摘要:本文主要学习如何在Windows环境中下载并安装Tomcat服务器. 下载 获取安装包 推荐去官网上下载Tomcat: htt ...