It seems that the word \"version\" in reference to Windows is used for different things. For example, the Windows 10 \"Anniversary Update\" is labeled \"Version 1607\" by Mi
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
string Version = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion", "ProductName", null);
Gives a name like "Windows 10 Enterprise".
according to MSDN official link there's a specific version number for each windows version out 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 a version of windows. this be can read from 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);
In addition to Scott's answer, you can also get the product name (ex. Windows 10 Pro) with this (*I take no credit as Scott is the one who mentioned the registry path + I'm reusing his code below):
using Microsoft.Win32;
string ProductName =
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
Console.WriteLine(ProductName);