winreg - SaveKey() returns WinError 1314 and creates empty file

26 views Asked by At

I don't know the reason of this behavior, but while running winreg's SaveKey function on Python 3.11 an empty file is written while returning WinError 1314 (A required privilege is not held by the client.)

I am running shell as an administrator (code below) and I do not understand why it fails. Can somebody help me to fix this?


>>> import winreg
>>> import ctypes
>>>
>>> # UAC activated
>>> ctypes.windll.shell32.IsUserAnAdmin()
True
>>>
>>> location = r"C:\Users\Key.reg"
>>>
>>> with winreg.OpenKey(winreg.HKEY_USERS, ".DEFAULT", access = winreg.KEY_ALL_ACCESS) as key:
...     winreg.SaveKey(key, location)
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: [WinError 1314] A required privilege is not held by the client.
>>>
>>> open(location).read()
''
>>> 
0

There are 0 answers