Deleting the Key
Now after clearing the key (deleting the values) it is time to Delete the key itself.
Python3
# importing required module import winreg as wrg # Store location of HKEY_CURRENT_USER location = wrg.HKEY_CURRENT_USER # Store complete path in soft soft = wrg.OpenKeyEx(location, r "SOFTWARE\\" ) key_1 = wrg.CreateKey(soft, "Geeks" ) # Deleting the foler Geeks del_key = wrg.DeleteKey(key_1, "") # Closing folder if key_1: wrg.CloseKey(key_1) |
DeleteKey also takes two parameters one is the key and the second one is the subkey, as we have already removed all those subkeys we have passed a blank string here (remember don’t even use space, it will be considered as a character).
Output: No Geeks key is there anymore.
Manipulating Windows Registry using winreg in Python
In this article, we will learn how to manipulate Windows Registry using winreg in Python.
What is windows registry?
It is a hierarchical database that holds low-level settings for the windows operating system and for applications in which the use of a registry is required. The device drivers, kernel, services, user interfaces, and security accounts manager can all use the registry.
IMPORTANT: As Windows Registry is a very sensitive place to do anything, do not change any value predefined by the Windows System. This article will just be for learning purposes of how Python can be used to create some new registry keys with user-defined values.
Windows registry can be used for different purposes, it can be accessed via typing regedit in the Run application.
Window opens after running “regedit” in run:
Contact Us