How to delete one application registry key from regedit using python script?

I am new to python. I want to remove a key that is in regedit using a python script.

Image of regedit tree for my application key

HKEY_CURRENT_USER | |_Software | |_Applications | |_Application |_Test1 |_Test2 

In this, I want to remove the Test1 key using a python script .

I used below script

 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) 

Error:

 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 

can anyone suggest a solution for this?

+6
source share
1 answer

Use backslash ( \ ) rather than slash ( / ). And _winreg.DeleteKey requires at least two arguments.

 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') 
+3
source

Source: https://habr.com/ru/post/956236/


All Articles