我有一些 32 位 C++ 代码来从注册表读取键/值对,如下所示:
// Get a handle to the required key
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\MyKey", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
// Look up the value for the key
bOK = (RegQueryValueEx(hKey, szKey, NULL, NULL, (PBYTE)szValue, &dwMax) == ERROR_SUCCESS);
// Release the handle
RegCloseKey(hKey);
}
由于它是一个 32 位应用程序,因此它从 SOFTWARE\WOW6432Node\MyKey 读取
在我将应用程序移植到 64 位之前,它工作得很好,所以它现在从 SOFTWARE\MyKey 读取。
我的安装程序不允许我将条目同时放入注册表的 32 位和 64 位部分,因此我需要 64 位应用程序继续从 WOW6432Node 获取其数据。
有人知道怎么做吗?
非常感谢 托尼·雷诺兹
最佳答案
如 32-bit and 64-bit Application Data in the Registry 下所述:
The KEY_WOW64_64KEY and KEY_WOW64_32KEY flags enable explicit access to the 64-bit registry view and the 32-bit view, respectively. For more information, see Accessing an Alternate Registry View.
后一个链接解释了这一点
These flags can be specified in the samDesired parameter of the following registry functions:
以下代码可以完成您的要求:
// Get a handle to the required key
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\MyKey", 0, KEY_READ | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
{
// ...
}
关于C++ 从 64 位应用程序读取 SOFTWARE\WOW6432 中的注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66283273/