64位:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
32位:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
这两个注册表存储的软件会重复,所以我们还要去重
我们使用python的标准库_winreg来获取软件安装列表,并输出到文件中租歼洞,代码如下:
#!/usr/bin/python
import os
import socket
import _winreg
#将软件安装列表输出到网盘改裂上
os.system(r'net use p: \\10.0.0.6\public password /user:Lc\tanjun')
#使用主机名命名软件安装列表
hostname = socket.gethostname()
file = open(r'P:\todo\temp\%s.txt' % hostname, 'a')
#需要遍历的两个注册表
sub_key = [r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', r'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall']
software_name = []
for i in sub_key:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, i, 0, _winreg.KEY_ALL_ACCESS)
for j in range(0, _winreg.QueryInfoKey(key)[0]-1):
try:
弊枯 key_name = _winreg.EnumKey(key, j)
key_path = i + '\\' + key_name
each_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_path, 0, _winreg.KEY_ALL_ACCESS)
DisplayName, REG_SZ = _winreg.QueryValueEx(each_key, 'DisplayName')
DisplayName = DisplayName.encode('utf-8')
software_name.append(DisplayName)
except WindowsError:
pass
#去重排序
software_name = list(set(software_name))
software_name = sorted(software_name)
for result in software_name:
file.write(result + '\n')
最近小弟在做一败激空个应用程序,就是仿造360软件管家,获取计算机里已安装软件列表,现思路如下,根据注册表路径:
针对x86系统,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
针对x64系统,HKEY_LOCAL_MACHINE\察瞎SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
分别获取已安装软件列表,然后按照以下步骤进行处理:
1.剔除service项,重复项,已安装补丁,如KB开头的子项(计划中,未能实现)
2.合并x86,x64.最终得到软件列表数铅桐据
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)