
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Windows Registry Access Using Python Winreg
As a versatile language and also availability of very large number of user supported modules, we find that python is also good at OS level programming. In this article we will see how python can access the registry of a windows operating system.
We need to import the module named winreg into the python environment.
In the below example we use the winreg module to first connect to the registry using the ConnectRegistry function and then access the registry using OpenKey function. Finally we design a for loop to print the result of the keys accessed.
Example
import winreg #connecting to key in registry access_registry = winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE) access_key = winreg.OpenKey(access_registry,r"SOFTWARE\Microsoft\Windows\CurrentVersion") #accessing the key to open the registry directories under for n in range(20): try: x =winreg.EnumKey(access_key,n) print(x) except: break
Output
Running the above code gives us the following result:
ApplicationFrame AppModel Appx Audio Authentication AutoRotation BITS Casting ClosedCaptioning CloudExperienceHost Component Based Servicing …….. …..
Advertisements