This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paulenet
Recipients paulenet
Date 2021-05-05.07:28:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620199728.07.0.7391681228.issue44046@roundup.psfhosted.org>
In-reply-to
Content
DETAILS:
"[WinError 5] Access is denied" error is thrown when user attempts to use a different Registry hive other than HKEY_CURRENT_USER.  The first example below will demonstrate that the code snippet works just fine and is implemented correctly.  However, when you try to run the exact same snippet, but with it pointed to HKEY_LOCAL_MACHINE, it will throw "[WinError 5] Access is denied" error.  I have seen plenty of variant examples on how you are supposed to write to the Registry, but when you attempt to do so to other hives, it simply does NOT work.  Complete demonstration below of it working, and not working...

# WORKING example:
registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
wholeKey = winreg.OpenKey(registry, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon', 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
winreg.SetValue(wholeKey, 'AutoAdminLogon', winreg.REG_SZ, '1')
winreg.CloseKey(wholeKey)


# NON-WORKING example:
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
wholeKey = winreg.OpenKey(registry, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon', 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
winreg.SetValue(wholeKey, 'AutoAdminLogon', winreg.REG_SZ, '1')
winreg.CloseKey(wholeKey)
History
Date User Action Args
2021-05-05 07:28:48paulenetsetrecipients: + paulenet
2021-05-05 07:28:48paulenetsetmessageid: <1620199728.07.0.7391681228.issue44046@roundup.psfhosted.org>
2021-05-05 07:28:48paulenetlinkissue44046 messages
2021-05-05 07:28:47paulenetcreate