如何获得注册表项的真实路径?
如果您在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在很大程度上是真实路径,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.
它取决于程序是否为 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