forked from aabbcc582/any-whim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path获取window安装软件地址.py
24 lines (24 loc) · 1.03 KB
/
获取window安装软件地址.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import winreg
sub_key = [
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall',
'SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall'
]
def get_install_list(key, root):
try:
_key = winreg.OpenKey(root, key, 0, winreg.KEY_ALL_ACCESS)
for j in range(0, winreg.QueryInfoKey(_key)[0]-1):
try:
each_key = winreg.OpenKey(root, key + '\\' + winreg.EnumKey(_key, j), 0, winreg.KEY_ALL_ACCESS)
displayname, REG_SZ = winreg.QueryValueEx(each_key, 'DisplayName')
install_loc, REG_SZ = winreg.QueryValueEx(each_key, 'InstallLocation')
display_var, REG_SZ = winreg.QueryValueEx(each_key, 'DisplayVersion')
yield displayname, install_loc, display_var
except WindowsError:
pass
except:
pass
for key in sub_key:
for root in [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]:
for name, local, var in get_install_list(key, root):
print(name, local, var)