Welcome, guest | Sign In | My Account | Store | Cart

The following program shows sample usage of the _winreg Wrapper.

Python, 38 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Tkinter
import tkMessageBox
import traceback
import winreg

################################################################################

def main(key):
    'Delete key and all empty parent keys.'
    Tkinter.Tk().withdraw()
    try:
        key, parent = delete(*key.rsplit('\\', 1))
        while empty(parent):
            key, parent = delete(*key.rsplit('\\', 1))
        tkMessageBox.showinfo('Info', 'Uninstall passed!')
    except:
        tkMessageBox.showerror('Error', traceback.format_exc())

def delete(key, subkey):
    'Delete key and all subkeys.'
    parent = winreg.Key(winreg.HKEY.CURRENT_USER, key)
    del parent.keys[subkey].keys
    del parent.keys[subkey]
    return key, parent

def empty(key):
    'Test for lack of values.'
    if key.values:
        return False
    for name in key.keys:
        if not empty(key.keys[name]):
            return False
    return True

################################################################################

if __name__ == '__main__':
    main('Software\\Atlantis Zero\\Kaos Rain\\Version 3')

This program will uninstall Kaos Rain (MKv3).