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

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

问题描述

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

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_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{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)

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

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?

推荐答案

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

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.

从MSDN:

在64位Windows的注册表项的部分将被分别保存32位应用程序和64位应用程序,并映射到使用注册表重定向器和注册表反射不同的逻辑注册表的看法,因为64位版本的应用程序可以使用不同的注册表项和值比32位版本。还有一些共享的是不定向或反射的注册表项。

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.

您可以阅读MSDN上的列表:注册表项受此影响WOW64 。不幸的是, SOFTWARE \微软\的Windows \ CurrentVersion \卸载未提及,但它的影响了。

You can read the list on MSDN: Registry Keys Affected by WOW64. Unfortunately the SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall is not mentioned but it's affected too.

解决方案
什么,你需要做的是明确的要求 RegOpenKeyEx的访问注册表的64位部分。这可以添加 KEY_WOW64_64KEY 标记您的来电(你可以访问32位注册表使用一个64位应用程序 KEY_WOW64_32KEY )。请注意,这个标志是不支持Windows 2000,然后,如果你的应用程序必须与(旧)的版本,你需要管理的情况下兼容。

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.

请参阅MSDN上的链接了解更多详情:访问备用注册表查看

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);

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

注意
请注意,您只能通过其的路径的没有任何标志使用本 HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \微软\的Windows \ CurrentVersion \卸载访问密钥。 因为 Wow6432 节点是的虚拟化的使用WOW64但你不应该依赖于这一点,它是稳定的,但它应该被视为一个实现细节节点随时可能更改。

Note
Note that you may access the key only via its path without any flags using this HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall. 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.

引用
- 注册表虚拟化的MSDN上
。 - 读者我觉得对这个职位感兴趣提示: HTTP://posh$c$c.org/2470 ,这对PowerShell的,但它说明了如何从32位应用程序访问WMI数据(相对于64位注册表部分)。

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.

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

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