从注册表中获取 Windows 版本的可靠方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31072543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reliable way to get Windows Version from registry
提问by skuallpa
I'm checking the windows version in an installer (made with NSIS) by checking the following registry key:
我正在通过检查以下注册表项来检查安装程序(使用 NSIS 制作)中的 Windows 版本:
HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
According to this postand this pagefrom MSDN, the currentVersion number for Windows 10 should be 10.0.
根据这篇文章和MSDN 的这个页面,Windows 10 的当前版本号应该是 10.0。
I just installed the Windows 10 Pro Insider Preview and the version number given in the registry is still 6.3, instead of 10.10 as it should.
我刚刚安装了 Windows 10 Pro Insider Preview,注册表中给出的版本号仍然是 6.3,而不是它应该的 10.10。
Is there another reliable way in registry to detect Windows 10?
注册表中是否有另一种可靠的方法来检测 Windows 10?
回答by magicandre1981
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.
不是读取值CurrentVersion
,而是读取Windows 10 下的新值CurrentMajorVersionNumber
(即 10)和CurrentMinorVersionNumber
(即 0)。这2 个键是 Windows 10 中的新项,用于从注册表检测 Windows 版本。
回答by pav
There's also a human-readable string in the registry called "ProductName"
注册表中还有一个人类可读的字符串,名为“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();
}
回答by Temujin
Try
尝试
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ReleaseId
Which gives me 10 and 1709.
这给了我 10 和 1709。
回答by John Whitmire
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
ifthe application manifest explicitlydesignates 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.
见彼得明亮的在文章https://arstechnica.com/information-technology/2014/11/why-windows-10-isnt-version-6-any-more-and-why-it-will-probably-work/为更深入地了解为什么你会看到你所做的答案。正如您已经从@magicandre1981 看到的那样,该CurrentMajorVersionNumber
键将为您提供所需的“10”。System.Environment.OSVersion
如果应用程序清单明确指定您的应用程序适用于 Windows 10,您可以获得 10.0 ,如参考文章中所述。没有它,Environment.OSVersion
将给您 6.2.9200,这与 Windows 8 相同。因此,您的 Windows 10 版本是 10.0、6.3 或 6.2,具体取决于您提问的方式。