Registry key EditionID has wrong value under WOW6432Node - by intention or bug? How to bypass?

Viewed 1527

I'm running Windows 10 Professional 1809 build 17763.

The value of HKLM\SOFTWARE\ WOW6432Node\Microsoft\Windows NT\CurrentVersion\EditionID is "Enterprise", which is wrong. HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\EditionID is "Professional", which is correct.

Is this a specific problem with my Windows installation? If not, how would you solve it if you would develop in 32 bit?

My original code is in C++. Because I didn't understand the issue first, I reimplemented it in C#. I would appreciate solutions in C# or C++ and I'm confident that I can solve the issue in one language given a solution in the other language. Thank you!

using System;
using System.Collections.Generic;
using Microsoft.Win32;

class Program
{
    static void Main(string[] args) {
        List<string> valueNames = new List<string> { "ProductName", "EditionID" };
        foreach (var valueName in valueNames) {
            string value = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", valueName, "Key not found");
            Console.WriteLine($"{valueName}: {value}");
        }
    }
}
//---- C++ version
#include "Registry.hpp" // Modern C++ Wrappers for Win32 Registry Access APIs by Giovanni Dicanio

const std::wstring subKey{ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" };
const std::wstring value{ L"EditionID" };
std::wstring ws = win32::RegGetString(HKEY_LOCAL_MACHINE, subKey, value);
this->windowsEdition = std::string(ws.begin(), ws.end());

EditionID should be "Professional", but is "Enterprise".

2 Answers

To access the 64 bit tree in the registry from a 32 bit application, You have to open the registry key using the option KEY_WOW64_64KEY.

C / C++ Example:

error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hKey);

Edit:

For .Net 3.5 or prior I found this: how-read-the-64-bit-registry-from-a-32-bit-application

Edit: C# (4.x) code:

RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).

I too was facing this issue, but following Ralph suggestion, the editionID is coming correctly for professionals version also.

C# Code:

var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
var editionID = key.GetValue("EditionID");
Related