简体   繁体   中英

python winreg unable to write to HKEY_CURRENT_USER

When using the following code block, I cannot write to HKEY_CURRENT_USER, but writing to HKEY_LOCAL_MACHINE is fine. There are no errors reported when attempting to write to HKEY_CURRENT_USER. There is no endpoint protection installed that would restrict writing to the registry.

Using python 3.9.1 and psutil 5.8.0 on Windows 10 64-bit and script is being executed as administrator.

import winreg
#HKEY_CURRENT_USER
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
    with winreg.CreateKeyEx(root, 'Software\AAA', 0, access = winreg.KEY_WOW64_64KEY | winreg.KEY_WRITE) as key:
        winreg.SetValueEx(key, "PATH", 0, winreg.REG_SZ, 'test')

# HKEY_LOCAL_MACHINE
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as root:
    with winreg.CreateKeyEx(root, 'Software\AAA', 0, access = winreg.KEY_WOW64_64KEY | winreg.KEY_WRITE) as key:
        winreg.SetValueEx(key, "PATH", 0, winreg.REG_SZ, 'test')

HKEY_CURRENT_USER

HKEY_LOCAL_MACHINE

C:\Users\admin\source\repos> python3 test.py

C:\Users\admin\source\repos>

Anyone have an idea of what I'm missing?

thanks!

Downgraded to python 3.8.7 and at first onset seems to be working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM