为什么我不能正确地HKCU 64位机器上读取32位注册表值? [英] Why can't I properly read 32bit registry values in HKCU on 64bit machine?

查看:647
本文介绍了为什么我不能正确地HKCU 64位机器上读取32位注册表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我难倒Windows 7的注册表问题,而各种问题和答案给我拿一些的方式出现,没有任何事情我已经看到了我的地址特定问题。我不知道其他Windows版本会影响这一问题,但我们都有win7x64机器。

I'm stumped on a windows 7 registry problem and while various questions and answers get me some of the way there, nothings I've seen addresses my particular issue. I don't know if other windows versions affects this problem, but we all have win7x64 machines.

我们在我们的工作中,一些C ++,部分有各种各样的工具C#中,一些Python(2.6)等。我们还运行32位和64位的工具组合。在过去,我们高兴地存储在HKLM注册表的信息。我们一直都在移动的东西到HKCU。我们已经有很多关于是否做到这一点的讨论,会影响UAC,等我们真的想尝试,使这一举措。这就是说:

We have a wide variety of tools at our work, some C++, some C#, some python (2.6), etc. We also run a mix of 32 and 64 bit tools. In the past, we've happily stored registry information in HKLM. We've been working on moving stuff into HKCU. We've had a lot of discussions about whether to do this, affects on UAC, etc. We really want to try and make this move. That said:

我们有麻烦读取/写入注册表项HKCU出/软件/ CompanyABC /应用程序的。我们有Python的使用_winreg写出注册表项,以上述位置设置应用写入。无论我们是否指定KEY_WRITE | KEY_WOW64_32KEY或只是KEY_WRITE,价值观得到软件写到HKCU /软件/ WOW6432Node / companyABC /应用程序。精细。

We are having trouble reading/writing registry keys out of HKCU/software/CompanyABC/App. We have a setup app write in python that writes out registry keys to the above location using _winreg. Whether or not we specify KEY_WRITE|KEY_WOW64_32KEY or just KEY_WRITE, the values get writte to HKCU/Software/WOW6432Node/companyABC/app. Fine.

然后我有试图读取这些值的C#应用​​程序。使用Microsoft.Win32.Registry,我打开子项(HKCU /软件/ CompanyABC /应用程序),我没有看到我的价值观。原来,我看到以下行为:

Then I have a C# app that tries to read these values. Using Microsoft.Win32.Registry, I open the subkey ('HKCU/Software/CompanyABC/app') and I don't see my values. Turns out that I'm seeing the following behavior:


  • 当读/写从HKLM注册表项,这些东西都只是工作。在Python应用程序会写入HKLM / Softare / Wow6432Node / CompanyABC /应用程序,以及C#代码将从该位置读取。这一切都使得真正意义上的太多,因为我们是如何构建我们的C#应用​​程序,并通过Python写的注册表值

  • 阅读/从HKCU写入注册表值,我得到不同的行为。该_winreg功能将写入HKCU / Sofrware / Wow6432Node / CompanyABC /应用程序,但是C#应用程序从HKCU /软件/ CompanyABC /应用程式阅读。在C#应用程序被构建为一个x86应用程序(而非任何CPU,而不是64位),所以我假定应用程序将得到正确重定向到wow6432Node,但它似乎没有没有。

后一些调查,似乎HKCU /软件是不同的。 文章似乎表明这一区域被共享而不是重定向。如果是这样的话,那么我不明白为什么我们的Python应用程序(再次使用_winreg)被写入到HKCU使用该Wow6432Node位置 - 它似乎像它应该没有到位的重定向来写它。我想,这可能是在_winreg的错误。

after some investigation, it appears that HKCU/Software is different. This article seems to indicate that this area is "shared" and not redirected. If that is the case, then I cannot understand why our python app (again, using _winreg) is writing to a location in HKCU that uses the Wow6432Node - it seems like it should be writing it without that redirection in place. I suppose that it could be a bug in _winreg.

我真的想避免我们的工具套结明确的WOW6432Node,但是这是我在今天的。任何人都可以向我解释正确,而不必诉诸硬编码路径到32位蜂巢我怎样才能使注册表从32位和64位程序到HKCU的工作访问?

I really want to avoid tacking on WOW6432Node explicitly in our tools, but that is where I am at today. Can anyone explain to me how I can make registry accesses from 32 and 64 bit processes into HKCU work correctly without having to resort to hard coded paths into the 32bit hive?

推荐答案

我从这个问题的意见明白,这个问题已经消失,对于其他任何人遇到这个问题,你可以使用的 Microsoft.Win32.OpenBaseKey 指定是否打开注册表的64位或32位部分在运行时,即使你的进程正在运行作为32位进程的64位计算机。

I understand from the comments on the question that this issue has gone away, for anyone else that encounters this question, you can use Microsoft.Win32.OpenBaseKey to specify whether to open the 64 or 32-bit portion of the registry when running on a 64-bit machine even if your process is running as a 32-bit process.

如果你总是想访问注册表的非WOW6432Node部分的钥匙,那么你可以安全地设置OpenBaseKey的视图参数 RegistryView .Registry64。这将正常工作在两个64位和32位操作系统。

If you always want to access the keys in the NON-WOW6432Node section of the registry, then you can safely set the View parameter of OpenBaseKey to RegistryView.Registry64. This will work correctly on both 64 and 32-bit OSes.

这篇关于为什么我不能正确地HKCU 64位机器上读取32位注册表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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