注册表项版本ID在WOW6432Node下具有错误的值 - 故意还是错误?如何绕过
Registry key EditionID has wrong value under WOW6432Node - by intention or bug? How to bypass?
我正在运行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");
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 如何故意触发 fgets() 中的错误?
- 注册表项版本ID在WOW6432Node下具有错误的值 - 故意还是错误?如何绕过