如何确定注册表项是否被 WOW64 重定向?

发布于 2024-08-29 17:22:24 字数 623 浏览 3 评论 0原文

是否可以确定给定的注册表项是否被重定向?

我的问题是我想从 32 位应用程序以通用方式枚举 32 位和 64 位注册表视图中的注册表项。我可以简单地打开每个密钥两次,首先使用 KEY_WOW64_64KEY,然后使用 KEY_WOW64_32KEY。但是,如果密钥未重定向,则会为您提供完全相同的密钥,并且最终会枚举完全相同的内容两次;这就是我试图避免的。

我确实找到了一些文档,但它看起来像是唯一的方法是检查配置单元并对键进行一系列字符串比较。我想到的另一种可能性是尝试在每个子项上打开 Wow6432Node;如果存在,则必须重定向密钥。即,如果我尝试打开 HKCU\Software\Microsoft\Windows,我会尝试打开以下键: HKCU\Wow6432Node、HKCU\Software\Wow6432Node、HKCU\Software\Microsoft\Wow6432Node 和 HKCU\Software\Microsoft\Windows\Wow6432Node。不幸的是,文档似乎暗示重定向密钥的子项不一定被重定向,因此路由也存在问题。

那么,我有什么选择呢?

Is it possible to determine whether or not a given registry key is redirected?

My problem is that I want to enumerate registry keys in both the 32-bit and 64-bit registry views in a generic manner from a 32-bit application. I could simply open each key twice, first with KEY_WOW64_64KEY and then with KEY_WOW64_32KEY. However, if the key is not redirected this gives you exactly the same key and you end up enumerating the exact same content twice; this is what I am trying to avoid.

I did find some documentation on it, but it looks like the only way is to examine the hive and do a bunch of string comparisons on the key. Another possibility I thought of is to try to open Wow6432Node on each subkey; if it exists then the key must be redirected. I.e. if I am trying to open HKCU\Software\Microsoft\Windows I would try to open the following keys:
HKCU\Wow6432Node, HKCU\Software\Wow6432Node, HKCU\Software\Microsoft\Wow6432Node, and HKCU\Software\Microsoft\Windows\Wow6432Node. Unfortunately, the documentation seems to imply that a child of a redirected key is not necessarily redirected so that route also has issues.

So, what are my options here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网白 2024-09-05 17:22:24

你的目标不明确。为什么需要从 32 位应用程序以通用方式枚举 32 位和 64 位注册表视图中的注册表项?您想在应用程序中使用 64 位值做什么?如果 x64 和 x86 密钥有一些不同的值,您会怎么做?这感觉很奇怪,或者说是错误的想法。

密钥重定向的一个重要原因是:不破坏 x86 应用程序的行为。例如:COM 使用CLSID 来查找给定接口的正确实现。其中,“正确”意味着它可以由调用者代码运行,即应该属于同一平台。这就是为什么 x64 和 x86 应该有不同的条目集。其他重定向键的原因类似。一般来说,对于 x86 和 x64 应用程序,这些重定向键必须不同

正如 Raymond Chen 所写,“在 64 位 Windows 上,32-位程序在仿真层中运行,如果你不喜欢这样,那就不要使用仿真器”,我完全同意他的建议。因此,如果您需要这样的东西,我最好的建议是从 x64 应用程序进行。但首先要重新考虑一下你是否真的需要它。

编辑:有 RegOpenKeyEx 您可能会发现有用。另请参阅“访问备用注册表”查看“ MSDN 文章。

Your goal is not clear. Why do you need to enumerate registry keys in both the 32-bit and 64-bit registry views in a generic manner from a 32-bit application? What do you want to do with 64-bit values in your application? What would you do if there is some different values for x64 and x86 key? It feels like strange or rather wrong idea.

Keys are redirected for important reason: to not break behavior of x86 applications. For example: CLSID is used by COM to find proper implementation for a given interface. Among other, "proper" means that it might be run by caller code i.e. should be of the same platform. That's why there should be different sets of entries for x64 and x86. Reasons for other redirected keys are similar. Generally speaking, those redirected keys has to be different for x86 and x64 applications.

As Raymond Chen wrote, "On 64-bit Windows, 32-bit programs run in an emulation layer, and if you don't like that, then don't use the emulator" and I totally agree with his advice. So my best advice if you need something like this, is to do it from x64 application. But first reconsider whether you really need it.

EDIT: There is samDesired parameter of RegOpenKeyEx that you might find useful. Also take a look at "Accessing an Alternate Registry View" MSDN article.

痴者 2024-09-05 17:22:24

您会遇到相当多的痛苦,这取决于操作系统版本。完整列表位于此处

You're in for a fair amount of pain, it depends on the operating system version. The full list is available here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文