我是python的新手。我想删除使用python脚本在regedit中的密钥。
我的应用程序密钥的注册表树视图
HKEY_CURRENT_USER
|
|_Software
|
|_Applications
|
|_Application
|_Test1
|_Test2
在此,我想使用python脚本删除Test1密钥。
我用过以下脚本
import _winreg
Key_Name=r'Software/Applications/Application/Test1'
Key=_winreg.OpenKey(_winreg.HKEY_CURRENT_USER, Key_Name, 0, _winreg.KEY_ALL_ACCESS)
_winreg.DeleteKey(key)
错误:
Traceback (most recent call last):
File "C:\Users\Test\workspace\Test\DeletePreferences.py", line 9, in <module>
key=_winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r'Software/Applications/Application/Test1', 0, _winreg.KEY_ALL_ACCESS)
WindowsError: [Error 2] The system cannot find the file specified
有人可以为此提出解决方案吗?
答案 0 :(得分:3)
使用反斜杠(\
),而不是正斜杠(/
)。并且_winreg.DeleteKey
至少需要两个参数。
import _winreg
Key_Name = r'Software\Qube Cinema\QubeMaster Pro'
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, Key_Name, 0, _winreg.KEY_ALL_ACCESS)
_winreg.DeleteKey(key, 'Test1')