从 32 位应用程序访问 64 位注册表 [英] Accessing 64 bit registry from 32 bit application

查看:27
本文介绍了从 32 位应用程序访问 64 位注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 C++ 中打开一个注册表项 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86416024FF}".它包含 java 64 位应用程序.该注册表项的完整路径是 "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall{26A24AE4-039D-4CA4-87B4-2F86416024FF}".

我们可以通过regedit查看这个路径.我用

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("软件\微软\Windows\当前版本\卸载\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),0, KEY_ALL_ACCESS, &hKey)

打开注册表;但它返回错误值(2).

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,文本(软件\微软\Windows\当前版本\卸载")...

返回成功结果.我能做什么?

解决方案

32 位应用程序和 64 位应用程序的注册表项是分开的,您无法(直接)从 32 位应用程序访问 64 位注册表.在您的情况下,注册表的 32 位部分中不存在所需的配置单元,那么您只能访问父文件夹.

来自 MSDN:

<块引用>

在 64 位 Windows 上,部分注册表项分别为 32 位应用程序和 64 位应用程序存储,并使用注册表重定向器和注册表反射映射到单独的逻辑注册表视图中,因为 64 位版本的应用程序可能使用与 32 位版本不同的注册表项和值.还有一些没有重定向或反映的共享注册表项.

您可以在 MSDN 上阅读该列表:受 WOW64 影响的注册表项.不幸的是,没有提到 SOFTWAREMicrosoftWindowsCurrentVersionUninstall 但它也受到了影响.

解决方案
您需要做的是明确询问 RegOpenKeyEx 以访问注册表的 64 位部分.这可以通过将 KEY_WOW64_64KEY 标志添加到您的调用中来完成(您可以使用 KEY_WOW64_32KEY 从 64 位应用程序访问 32 位注册表).请注意,Windows 2000 不支持此标志,如果您的应用程序必须与该(旧)版本兼容,则您必须管理该案例.

有关详细信息,请参阅 MSDN 上的此链接:访问备用注册表视图.

为方便起见,只需更改您的电话:

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("软件\微软\Windows\当前版本\卸载\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),0, KEY_ALL_ACCESS, &hKey);

到:

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("软件\微软\Windows\当前版本\卸载\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),0, KEY_ALL_ACCESS |KEY_WOW64_64KEY, &hKey);

注意
请注意,您只能通过它的 路径 访问密钥,而没有使用此 HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall 的任何标志.因为Wow6432节点是WOW64使用的虚拟化节点,但你不应该依赖它,它是稳定的,但它应该被视为一个可能会更改的实现细节.>

参考资料
- MSDN 上的注册表虚拟化.
- 读者我在这篇文章中发现了有趣的提示:http://poshcode.org/2470,它适用于 PowerShell 但它解释了如何从 32 位应用程序访问 WMI 数据(相对于 64 位注册表部分).

I need to open a registry entry "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86416024FF}" in c++. It contains the java 64 bit application. The full path of that registry entry is "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall{26A24AE4-039D-4CA4-87B4-2F86416024FF}".

We can view this path through regedit. I use

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
    TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),
    0, KEY_ALL_ACCESS, &hKey)

for open the registry; But it returns error value (2).

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")...

returns a success result. What can i do?

解决方案

The registry keys for 32 bit and 64 applications are separated, you can't access (directly) the 64 bit registry from your 32 bit application. In your case the required hive doesn't exist in the 32 bit part of the registry then you can access the parent folder only.

From MSDN:

On 64-bit Windows, portions of the registry entries are stored separately for 32-bit application and 64-bit applications and mapped into separate logical registry views using the registry redirector and registry reflection, because the 64-bit version of an application may use different registry keys and values than the 32-bit version. There are also shared registry keys that are not redirected or reflected.

You can read the list on MSDN: Registry Keys Affected by WOW64. Unfortunately the SOFTWAREMicrosoftWindowsCurrentVersionUninstall is not mentioned but it's affected too.

Solution
What you have to do is to explicitly ask RegOpenKeyEx to access the 64 bit part of the registry. This can be done adding the KEY_WOW64_64KEY flag to your call (you can access the 32 bit registry from a 64 bit application using KEY_WOW64_32KEY). Please note that this flag is not supported on Windows 2000 then if your application must be compatible with that (old) version you have to manage the case.

See this link on MSDN for further details: Accessing an Alternate Registry View.

To make it easy, simply change your call from:

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
    TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),
    0, KEY_ALL_ACCESS, &hKey);

to:

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
    TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86416024FF}"),
    0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);

Note
Note that you may access the key only via its path without any flags using this HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall. Because the Wow6432 node is the virtualized node used by WOW64 but you shouldn't rely on this, it's stable but it should be considered an implementation detail subject to change.

References
- Registry Virtualization on MSDN.
- Readers my find interesting tips on this post: http://poshcode.org/2470, it's for the PowerShell but it explains how to access WMI data (relative to the 64 bit registry part) from a 32 bit application.

这篇关于从 32 位应用程序访问 64 位注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆