python读取windows安装的所有应用

2020-10-20  本文已影响0人  Aedda
import winreg

#需要遍历的两个注册表
sub_key = [r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', r'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall']
for i in sub_key:
    key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, i)
    for j in range(winreg.QueryInfoKey(key)[0]):
        try:
            each_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f'{i}\\{winreg.EnumKey(key, j)}')
            DisplayName = winreg.QueryValueEx(each_key, 'DisplayName')[0]
            print(DisplayName.encode('utf-8'))
        except WindowsError:
            pass

上一篇 下一篇

猜你喜欢

热点阅读