Changing a 64-bit registry with 32-bit Python

It’s hard for me to understand this. If I'm right, 32-bit Python cannot run code and change registry values ​​on a 64-bit basis. Did I understand correctly? Or is there a switch for inclusion in which this function is enabled?

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

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

Thanks oz

+4
source share
1 answer

As the MSDN article you are referring to, it is explained that in 64-bit Windows there are two types of registry: one for 32-bit and one for 64-bit. By default, a 32-bit application (for example, your Python script executed by the 32-bit Python interpreter) will gain access to the 32-bit representation. You can force it to access the 64-bit view using the flags mentioned in the MSDN article. To use these flags, you need to call _winreg.OpenKey , _winreg.CreateKeyEx or _winreg.DeleteKeyEx with the correct parameters, for example.

 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.

+6
source

Source: https://habr.com/ru/post/1386344/


All Articles