averainy's Blog

averainy

16 Oct 2023

Get Windows Installed Software by Winreg

def getInstalledProgramsFromRegistry():
    registry_key =r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
    registry_key_64bit = r"Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
    key_list=[]
    key_list.append(winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, registry_key))
    key_list.append(winreg.OpenKey(winreg.HKEY_CURRENT_USER, registry_key))

    is_64bit = platform.architecture()[0].startswith('64')
    if(is_64bit):
        key_list.append(winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, registry_key_64bit))
    for key in key_list:
        i = 0
        while True:
            try:
                key_name = winreg.EnumKey(key, i)
                sub_key = winreg.OpenKey(key, key_name)
                try:
                    value = winreg.QueryValueEx(sub_key, "DisplayName")[0]
                except Exception as e:
                    value = ""
                print("{0}:{1}".format(key_name, value))
                i = i + 1
            except Exception as e:
                print(e)
                break