Change 64bit Registry from 32bit Python

余生长醉 提交于 2019-12-07 11:32:11

问题


I am having difficulty do understand this. If I'm correct, A 32bit Python can't run a code and change registry values in 64bit. Do I get it right? Or is there a switch to turn on in which enables this functionality?

There is this: http://msdn.microsoft.com/en-us/library/aa384129%28v=VS.85%29.aspx

But how do I use it with the following code? http://www.blog.pythonlibrary.org/2010/03/20/pythons-_winreg-editing-the-windows-registry/

Thanks, Oz


回答1:


As the MSDN article you linked to explains, 64bit Windows has two registry views, one for 32bit and one for 64bit. By default a 32bit application (e.g. your Python script being executed by a 32bit Python interpreter) will access the 32bit view. You can force it to access the 64bit view using the flags mentioned in the MSDN article. To be able to use these flags you need to call _winreg.OpenKey, _winreg.CreateKeyEx or _winreg.DeleteKeyEx with the correct parameters, e.g.

handle = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "your_sub_key", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)

See the _winreg documentation for more information.



来源:https://stackoverflow.com/questions/8506646/change-64bit-registry-from-32bit-python

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