从 32 位 Python 更改 64 位注册表 [英] Change 64bit Registry from 32bit Python

查看:32
本文介绍了从 32 位 Python 更改 64 位注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解这一点.如果我是对的,32 位 Python 无法在 64 位中运行代码和更改注册表值.我做对了吗?或者是否有一个开关可以启用此功能?

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?

有这个:http://msdn.microsoft.com/en-us/library/aa384129%28v=VS.85%29.aspx

但是我如何在下面的代码中使用它呢?http://www.blog.pythonlibrary.org/2010/03/20/pythons-_winreg-editing-the-windows-registry/

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

谢谢,盎司

推荐答案

正如您链接到的 MSDN 文章所解释的那样,64 位 Windows 有两个注册表视图,一个用于 32 位,一个用于 64 位.默认情况下,32 位应用程序(例如,由 32 位 Python 解释器执行的 Python 脚本)将访问 32 位视图.您可以使用 MSDN 文章中提到的标志强制它访问 64 位视图.为了能够使用这些标志,您需要使用正确的参数调用 _winreg.OpenKey_winreg.CreateKeyEx_winreg.DeleteKeyEx,例如

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)

有关详细信息,请参阅_winreg 文档.

See the _winreg documentation for more information.

这篇关于从 32 位 Python 更改 64 位注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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