我运行的是 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/