Disable registry redirection to Wow6432Node in Python

匆匆过客 提交于 2019-12-11 10:56:27

问题


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"))

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?

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.


回答1:


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)

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.



来源:https://stackoverflow.com/questions/28280377/disable-registry-redirection-to-wow6432node-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!