Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change 64bit Registry from 32bit Python

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

like image 896
oz123 Avatar asked Dec 14 '11 15:12

oz123


1 Answers

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.

like image 170
Florian Brucker Avatar answered Sep 21 '22 16:09

Florian Brucker