如何获得注册表项的真实路径?

发布于 2024-08-17 06:13:18 字数 348 浏览 2 评论 0原文

如果您在 64 位计算机上运行 32 位应用程序(我使用的是 Windows 7)并且您编写此代码,

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\XXX")

它实际上会从中获取密钥

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\XXX

,而不是

HKEY_LOCAL_MACHINE\SOFTWARE\XXX

按顺序给出注册表密钥,我如何计算出注册表中的真实路径?

If you are running a 32 bit app on a 64 bit machine (I am using windows 7) and you write this code

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\XXX")

it will actually get the key from

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\XXX

and not

HKEY_LOCAL_MACHINE\SOFTWARE\XXX

Progromatically given a RegistryKey how do i work out the true path in the registry?

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

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

发布评论

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

评论(2

陌伤浅笑 2024-08-24 06:13:18

这在很大程度上是真实路径,32 位应用程序将始终访问该子项中的注册表项。获得 64 位应用程序所看到的价值在技术上是可行的,但使用 .NET 则不然。您必须 P/Invoke RegOpenKeyEx() 等才能指定 KEY_WOW64_64KEY 标志。


更新:在.NET 4.0 中使用RegistryKey.OpenBaseKey() 进行了解决。 RegistryView 参数允许您指定所需的视图。在这种情况下,您将使用RegistryView.Registry64。

It is very much the True Path, a 32-bit app will always access the registry key in that subkey. Getting the value that a 64-bit app would see is technically possible, just not with .NET. You'll have to P/Invoke RegOpenKeyEx() et al so you can specify the KEY_WOW64_64KEY flag.


UPDATE: addressed in .NET 4.0 with RegistryKey.OpenBaseKey(). The RegistryView argument lets you specify the view you want. You'd use RegistryView.Registry64 in this case.

楠木可依 2024-08-24 06:13:18

它取决于程序是否为 32 位或 64 位 Windows 编译以及是否在 32 位或 64 位 Windows 上运行。看看下面是否有帮助:

http ://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3

It is a function of whether or not the program was compiled for 32 or 64 bit Windows and whether it's running on 32 or 64 bit Windows. See if below helps:

http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3

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