0

I want to get underlying machine OS info along with its other details in C# .NET Code.

When ran the below code on Windows 10 Pro machine, it returns the wrong value as "Windows 10 Enterprise".

Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();

Is there any other key to be queried on Registry? Else it has manually interpreted through its minor & major version details?

Vaibhav More
  • 212
  • 1
  • 14
  • Does this answer your question? [Detect Windows version in .net](https://stackoverflow.com/questions/2819934/detect-windows-version-in-net) – nilsK Feb 18 '21 at 15:42
  • Also read the 'Important note' in the [accepted answer](https://stackoverflow.com/a/2819962/2590375) – nilsK Feb 18 '21 at 15:43
  • @nilsK, that doesn't provide the exact answer with edition details like Windows 10 Pro. Also, why doesn't the above doesn't work on the specific machine to get the necessary edition? It provides OS name like Win 10 but not the edition details correctly. – Vaibhav More Feb 24 '21 at 06:59

1 Answers1

0

It requires explicitly to be queried on a 32-bit or 64-bit registry depending upon your system.

This solution does not use any hacks to get the OS Edition. It gives exact same value which you can see in the registry when you navigate to the path.

Eg. In my case it returns, "Windows 10 Pro"

RegistryKey localKey = null;
if (Environment.Is64BitOperatingSystem) {
     localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
     RegistryView.Registry64);
} else {
     localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
     RegistryView.Registry32);
}
var productName = localKey.OpenSubKey(@ "SOFTWARE\Microsoft\Windows 
                  NT\CurrentVersion").GetValue("ProductName").ToString();
Console.WriteLine("ProductName : " + productName);
Vaibhav More
  • 212
  • 1
  • 14