我试图在python中模拟以下注册表脚本。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Open with notepad]
[HKEY_CLASSES_ROOT\*\shell\Open with notepad\command]
@="notepad %1"
我的尝试看起来像这样。
import winreg as wreg
reg = wreg.ConnectRegistry(None, wreg.HKEY_CLASSES_ROOT)
root = wreg.OpenKey(reg, r'\*\shell', 0, wreg.KEY_ALL_ACCESS)
key = wreg.CreateKey(root, r'Open with notepad')
wreg.SetValue(key, None, wreg.REG_SZ, '')
wreg.FlushKey(key)
key2 = wreg.CreateKey(root, r'Open with notepad\command')
wreg.SetValue(key2, None, wreg.REG_SZ, 'notepad %1')
wreg.FlushKey(key2)
root.Close()
key.Close()
key2.Close()
然而,它似乎没有做任何事情。没有显示错误,但根据regedit也没有将任何密钥添加到注册表中。
我做错了什么?