Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_winreg.CreateKey problem in Python

I'm trying to create a key like this

_winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Shared Tools\\MSCONFIG\\startupreg\\test\\')

and the key is beeing created here

HKLM\Software\Wow6432Node\Microsoft\Shared Tools\MSCONFIG\startupreg\test\

why?

Yes, Windows 7 64x here

like image 836
Bruno 'Shady' Avatar asked May 19 '26 08:05

Bruno 'Shady'


1 Answers

You can read the article Glenn referred to, but it will not be much help.

What you probably need is proper access rights combined with access to the 64-bit registry view:

with _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, 
                             r"Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\", 
                             0, 
                             _winreg.KEY_WOW64_64KEY | _winreg.KEY_ALL_ACCESS) as key:

    _winreg.SetValueEx(key, "testValueName", 0, _winreg.REG_SZ, "value")

Please note the combination of those _winreg.KEY_WOW64_64KEY | _winreg.KEY_ALL_ACCESS.

like image 172
Alex Okrushko Avatar answered May 23 '26 00:05

Alex Okrushko