Play With Windows Registry using Python

 

Code Example


Note**: Only For Windows User

Suppose we are creating one windows application and that has some license key for what is the best place to keep that key so that no can hack it or reuse it.

Let's start .....

We will be creating a Function for a different purpose 


Example :

# test.py


import winreg as wreg


def store_data_in_windows_registry():

    my_key = "my-demo-key"

    data = "Test data"

    key = wreg.CreateKey(wreg.HKEY_CURRENT_USER, my_key)

    wreg.SetValue(key, my_key, wreg.REG_SZ, data)

    print("Data Set in Register")


def get_data_from_windows_registry():

    my_key = "my-demo-key"

    try:

        key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, my_key)

        return wreg.QueryValue(key, my_key)

    except:

        return "No Data Found"


def clear_data_from_windows_registry():

    my_key = "my-demo-key"

    key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, my_key)

    try:

        wreg.DeleteKey(key, my_key)

    except:

        print("Deleted From Regisrty")



# running 

store_data_in_windows_registry()

print("Trying fetch Data from Registry")

print(get_data_from_windows_registry())

print("Clearing Registry")

clear_data_from_windows_registry()


Screenshot:




Enjoy Edge-cutting Technology 😉

Quiz Level 1

Quiz Level 2


Request Me


Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python