Reliable way to get Windows Version from registry
Asked Answered
T

4

17

I'm checking the windows version in an installer (made with NSIS) by checking the following registry key:

HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"

According to this post and this page from MSDN, the currentVersion number for Windows 10 should be 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.

Is there another reliable way in registry to detect Windows 10?

Tearle answered 26/6, 2015 at 11:53 Comment(6)
there is a new value CurrentMajorVersionNumber which is 10 and CurrentMinorVersionNumber which is 0 in my Win10 VM.Rhubarb
Why is reading it from the registry a requirement?Magnesia
Thanks @magicandre1981. This is what I needed. I checked if these keys exist and the value of these keys.Tearle
ok, I posted it as answer.Rhubarb
Or use the version plugin: nsis.sourceforge.net/Version_plug-inRefractory
@Anders, reading the registry is often the only mechanism that's reliable from outside the running OS.Ise
R
18

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.

Rhubarb answered 30/6, 2015 at 16:0 Comment(0)
P
3

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();
}
Prepositor answered 25/7, 2017 at 9:27 Comment(0)
F
3

Try

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

Which gives me 10 and 1709.

Fraternize answered 13/11, 2017 at 18:13 Comment(1)
At least for Win10 Enterprise, the ProductName is "Windows 10 Enterprise"...Salientian
C
2

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.

Catastrophe answered 16/1, 2018 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.