注册表项版本ID在WOW6432Node下具有错误的值 - 故意还是错误?如何绕过

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

本文关键字:故意 错误 何绕过 ID 版本 WOW6432Node 有错误 注册表      更新时间:2023-10-16

我正在运行Windows 10 Professional 1809 build 17763。

HKLMSOFTWARE WOW6432NodeMicrosoftWindows NTCurrentVersionEditionID的值是"Enterprise",这是错误的。 HKLMSOFTWAREMicrosoftWindows NTCurrentVersionEditionID"Professional",这是正确的。

这是我的 Windows 安装的特定问题吗?如果没有,如果你用 32 位开发,你会如何解决它?

我的原始代码是C++的。因为我首先不了解这个问题,所以我在 C# 中重新实现了它。我希望 C# 或 C++ 中的解决方案,我相信我可以用一种语言解决问题,因为另一种语言的解决方案。谢谢!

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_MACHINESOFTWAREMicrosoftWindows NTCurrentVersion", 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应该是"Professional",但"Enterprise"

若要从 32 位应用程序访问注册表中的 64 位树,必须使用选项 KEY_WOW64_64KEY 打开注册表项。

C/C++示例:

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

编辑:

对于 .Net 3.5 或更早版本,我发现:如何从 32 位应用程序读取 64 位注册表

编辑:C# (4.x) 代码:

RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).
<</div> div class="answers">

我也遇到了这个问题,但根据 Ralph 的建议,版本ID 也适用于专业版本。

C# 代码:

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