C# detect latest .net framework installed on PC(count)

网友投稿 604 2022-09-11

C# detect latest - framework installed on PC(count)

C# detect latest - framework installed on PC(count)

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!";

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:彻底卸载WIN10杀毒软件Windows Defender的批处理,来自GitHub
下一篇:Elasticsearch-基础介绍及索引原理分析
相关文章

 发表评论

暂时没有评论,来抢沙发吧~