Editing the Windows Registry with winreg in Python had a strange result

65 views Asked by At

New to Python, was trying to figure if it's possible to modify an existing registry value, things turned out quite odd as the script keeps returning that the value was indeed modified, but when I go to Regedit everything is the same.

First I ran this test:

with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as hkey:
    with winreg.OpenKey(hkey, r"SOFTWARE\\GUU\\", 0, winreg.KEY_ALL_ACCESS) as guu:
        Client = winreg.QueryValueEx(guu, "Client")
        print(Client[0])

That resulted in the expected output "qBitTorrent" which was the data within the Client value. Then I run this code in hopes to modify it:

with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as hkey:
    with winreg.OpenKey(hkey, r"SOFTWARE\\GUU\\", 0, winreg.KEY_ALL_ACCESS) as guu:
        new_path_value = "Hiiiii"
        winreg.SetValue(guu, "Client", winreg.REG_SZ, new_path_value)
        if guu:
            winreg.CloseKey(guu)

The code ended with no errors. Re-running the previous test now outputs "Hiiiii" as the new data for Client, but on Regedit it still shows up as qBitTorrent, but still whenever I print the "Client" data the output is always "Hiiiii" as if the alteration actually happened succesfully.

0

There are 0 answers