Reliable way to get Windows Version from registry

这一生的挚爱 提交于 2019-11-27 14:47:11

Instead of reading the value CurrentVersion, read the new values CurrentMajorVersionNumber (which is 10) and CurrentMinorVersionNumber (which is 0) under Windows 10. Those 2 keys are new in Windows 10 to detect Windows Version from Registry.

There's also a human-readable string in the registry called "ProductName"

using Microsoft.Win32;
private string getOSInfo()
{
   string registry_key = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
   var key = Registry.LocalMachine.OpenSubKey(registry_key);
   var value = key.GetValue("ProductName");
   return value.ToString();
}

Try

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ReleaseId

Which gives me 10 and 1709.

See Peter Bright's article at https://arstechnica.com/information-technology/2014/11/why-windows-10-isnt-version-6-any-more-and-why-it-will-probably-work/ for more insight on why you see the answers you do. As you already saw from @magicandre1981, the CurrentMajorVersionNumber key will give you the "10" you want. You can get 10.0 from System.Environment.OSVersion if the application manifest explicitly designates your app for Windows 10, as stated in the referenced article. Without it, Environment.OSVersion will give you 6.2.9200, which is the same as Windows 8. So, your Windows 10 version is 10.0, 6.3, or 6.2, depending on how you ask the question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!