c# - 注册表项 EditionID 在 WOW6432Node 下有错误的值 - 是故意还是错误?如何绕过?

标签 c# c++ windows registry wow64

我运行的是 Windows 10 Professional 1809 build 17763。

HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\EditionID 的值为"Enterprise",这是错误的。 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\EditionID"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_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 应该是 "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 或之前的版本,我发现了这个:how-read-the-64-bit-registry-from-a-32-bit-application

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

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

关于c# - 注册表项 EditionID 在 WOW6432Node 下有错误的值 - 是故意还是错误?如何绕过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54174567/

相关文章:

c# - 如何禁止使用属性 setter ?

C++ 模板函数字符串类型不匹配?

c++ - 使用 boost::python 将回调从 python 传递到 c++

windows - Windows 8 Store App 中的 XAML 对齐

windows - 在 Wix 中运行自定义操作之前添加用户

c# - Excel 2007 以编程方式最小化功能区但不是菜单栏

c# - 通过电子邮件整合两个系统

c# - 如何制作可滚动的文本框列表?

c++ - const char* 与 char* (C++)

windows - 如何在GO中实现跨平台文件锁定