在 Python 中禁用注册表重定向到 Wow6432Node [英] Disable registry redirection to Wow6432Node in Python
问题描述
我正在尝试访问 64 位系统上 HKEY_LOCAL_MAHINE\SOFTWARE... 下的注册表项.我有以下代码,但从结果来看,即使我的代码中有 _winreg.DisableReflectionKey(_winreg.OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE")),它也被重定向到 Wow6432Node.
I'm trying to access registry keys under HKEY_LOCAL_MAHINE\SOFTWARE... on a 64 bits system. I have following code but judging by the results it gets redirected to Wow6432Node even though I have _winreg.DisableReflectionKey(_winreg.OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE")) in my code.
import _winreg
import wmi
c = wmi.WMI(computer="localhost", namespace="root/default").StdRegProv
_winreg.DisableReflectionKey(_winreg.OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE"))
result, names = c.EnumKey(hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName="SOFTWARE")
print names
_winreg.EnableReflectionKey(_winreg.OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE"))
我已阅读以下案例,但似乎那里描述的解决方案对作者或我都不起作用:如何在 Python 上关闭注册表重定向?
I have read the following case but it seems that the solution described there doesn't work for either the author or for me: How can I turn off registry redirection on Python?
还检查了 _winreg 文档,但没有具体示例,我也不知道自己做错了什么.有任何想法吗?抱歉,我没有权限在现有案例中发表评论,不得不打开一个新案例.
Also checked _winreg documentation, but there are no specific examples and I have no idea what I'm doing wrong. Any ideas? Sorry, I didn't have permission to comment in the existing case and had to open a new one.
推荐答案
看起来_winreg.KEY_READ | _winreg.KEY_WOW64_64KEY"可以完成这项工作.更准确地说,您需要以这种方式打开钥匙:
It looks like "_winreg.KEY_READ | _winreg.KEY_WOW64_64KEY" does the job. To be more precise you need to open the key this way:
_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)
我在访问 localhost 注册表时成功了.但是,我仍然没有弄清楚如何连接到域上的远程注册表.尝试使用 _winreg.ConnectRegistry,但不断收到拒绝访问错误.
I got this working when accessing the localhost registry. However, I still haven't figured out how to connect to remote registry on the domain. Trying to use _winreg.ConnectRegistry, but keep getting access denied error.
这篇关于在 Python 中禁用注册表重定向到 Wow6432Node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!