[英]C++ read a Registry entry in SOFTWARE\WOW6432 from a 64-bit app
I've got some 32-bit C++ code to read a Key/Value pair from the Registry as follows:我有一些 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);
}
As it's a 32-bit app it reads from SOFTWARE\WOW6432Node\MyKey由于它是一个 32 位应用程序,它从 SOFTWARE\WOW6432Node\MyKey 读取
This was working fine until I ported the app to 64-bit, so it now reads from SOFTWARE\MyKey.在我将应用程序移植到 64 位之前,它工作正常,所以它现在从 SOFTWARE\MyKey 读取。
My installer won't let me put entries into both the 32-bit and 64-bit parts of the Registry, so I need the 64-bit app to go on getting its data from WOW6432Node.我的安装程序不允许我将条目同时放入注册表的 32 位和 64 位部分,因此我需要 go 的 64 位应用程序从 WOW6432Node 获取其数据。
Does anyone know how to do this?有谁知道如何做到这一点?
Many thanks Tony Reynolds非常感谢托尼雷诺兹
As documented under 32-bit and 64-bit Application Data in the Registry :如注册表中的 32 位和 64 位应用程序数据中所述:
The KEY_WOW64_64KEY and KEY_WOW64_32KEY flags enable explicit access to the 64-bit registry view and the 32-bit view, respectively.
KEY_WOW64_64KEY 和 KEY_WOW64_32KEY 标志分别启用对 64 位注册表视图和 32 位视图的显式访问。 For more information, see Accessing an Alternate Registry View .
有关详细信息,请参阅访问备用注册表视图。
The latter link explains that后一个链接解释说
These flags can be specified in the samDesire d parameter of the following registry functions:
这些标志可以在以下注册表函数的samDesire d 参数中指定:
The following code accomplishes what you are asking for:以下代码完成了您的要求:
// 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)
{
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.