问题描述
使用以下代码块时,我无法写入 HKEY_CURRENT_USER,但写入 HKEY_LOCAL_MACHINE 没问题。尝试写入 HKEY_CURRENT_USER 时没有报告错误。没有安装会限制写入注册表的端点保护。
在 Windows 10 64 位上使用 python 3.9.1 和 psutil 5.8.0,脚本以管理员身份执行。
import winreg
#HKEY_CURRENT_USER
with winreg.ConnectRegistry(None,winreg.HKEY_CURRENT_USER) as root:
with winreg.CreateKeyEx(root,'Software\AAA',access = winreg.KEY_WOW64_64KEY | winreg.KEY_WRITE) as key:
winreg.SetValueEx(key,"PATH",winreg.REG_SZ,'test')
# HKEY_LOCAL_MACHINE
with winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE) as root:
with winreg.CreateKeyEx(root,'test')
C:\Users\admin\source\repos> python3 test.py
C:\Users\admin\source\repos>
有人知道我缺少什么吗?
谢谢!
解决方法
降级到 python 3.8.7,一开始似乎工作正常。