How to get the version of Windows - as in "Windows 10, version 1607"?

It seems that the word "version" in relation to Windows is used for different things. For example, Windows 10 “Anniversary Update” is designated “Microsoft Version 1607” ( here ). But if I try to get the “Version” (on a PC with the Anniversary Update installed) using the following code, nothing is returned that looks like “1607”.

// Get Version details Version ver = os.Version; Console.WriteLine("Major version: " + ver.Major); Console.WriteLine("Major Revision: " + ver.MajorRevision); Console.WriteLine("Minor version: " + ver.Minor); Console.WriteLine("Minor Revision: " + ver.MinorRevision); Console.WriteLine("Build: " + ver.Build); 

I get this:

 Major version: 6 Major Revision: 0 Minor version: 2 Minor Revision: 0 Build: 9200 

How to get the version of Windows 10, as in "Version 1607"?

Thanks!

+8
source share
4 answers

according to the official MSDN link, a version number is defined for each version of Windows there. in dot net, this can be read using the Environment.OSVersion object.

 Console.WriteLine("OSVersion: {0}", Environment.OSVersion); //output: OSVersion: Microsoft Windows NT 6.2.9200.0 

What you are looking for is called ReleaseID, not the window version. this can be read from the registry key:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ReleaseId

 using Microsoft.Win32; string releaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString(); Console.WriteLine(releaseId); 
+18
source

In addition to Scott's answer, you can also get the name of the product (e.g. Windows 10 Pro) with this (* I don’t think Scott is the one who mentioned the registry path + I reuse its code below):

 using Microsoft.Win32; string ProductName = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString(); Console.WriteLine(ProductName); 
0
source
  private static ManagementObject GetMngObj(string className) { var wmi = new ManagementClass(className); foreach (var o in wmi.GetInstances()) { var mo = (ManagementObject)o; if (mo != null) return mo; } return null; } public static string GetOsVer() { try { ManagementObject mo = GetMngObj("Win32_OperatingSystem"); if (null == mo) return string.Empty; return mo["Version"] as string; } catch (Exception e) { return string.Empty; } } 

How to use:

 Console.WriteLine(GetOsVer()); 

Result: 10.0.0.1299

0
source
 string Version = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion", "ProductName", null); 

Gives a name like "Windows 10 Enterprise".

-1
source

Source: https://habr.com/ru/post/1257465/


All Articles