1

I can read the Windows "product name" from the registry in C# using

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

I am running a 64 bit version of Windows Pro, but from a 32 bit application, this returns "Windows 10 Enterprise".

In fact, if I look in the registry, I can see that in the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

the value is "Windows 10 Pro", but in the key

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion

it is "Windows 10 Enterprise".

Does this make any sense?

Is there a simple (i.e. one line) way to get the real product name?

Phil Jollans
  • 3,605
  • 2
  • 37
  • 50
  • Does this answer your question? [How to get the "friendly" OS Version Name?](https://stackoverflow.com/questions/577634/how-to-get-the-friendly-os-version-name) – tenfour Apr 07 '21 at 07:17

2 Answers2

0

You can use GetProductInfo as long as you don't want to support OS versions prior to Windows Vista.

icebp
  • 1,608
  • 1
  • 14
  • 24
0

I don't know why the 32-bit and 64-bit hives are different. On my fresh install of Windows 10 Pro x64 21H1 the 32-bit version has an Edition of "Enterprise" and ProductName of "Windows 10 Enterprise". The 64-bit registry had the correct "Pro" values.

My 32-bit process defaulted to the the 32-bit registry on the x64 OS. I wanted to cover the situation if the code really did run on a 32-bit OS.

It's not a one liner, but I used this code to select the registry based on the OS.

var hklm64 = RegistryKey.OpenBaseKey(
  RegistryHive.LocalMachine,
  Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32
);

RegistryKey rk = hklm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");

string product = (string)rk.GetValue("ProductName");
string edition = (string)rk.GetValue("Edition");
Rich Shealer
  • 3,362
  • 1
  • 34
  • 59