首页 > 编程语言 > 详细

Python获取软件安装列表

时间:2020-12-02 17:31:17      阅读:73      评论:0      收藏:0      [点我收藏+]

python获取软件安装列表

#!/usr/bin/python

import os
import socket
import winreg

# 检测主机名,并将主机名作文检测结果的文件名
file = open(rd:\123Soft.txt)

# 定义检测位置
sub_key = [rSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,
           rSOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall]

software_name = []
adobe = adobe
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)
            DisplayVersion, REG_SZ1 = winreg.QueryValueEx(each_key, DisplayVersion)
            Publisher, REG_SZ2 = winreg.QueryValueEx(each_key, Publisher)
            InstallDate, REG_SZ3 = winreg.QueryValueEx(each_key, InstallDate)
            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:
    print(result.decode("utf-8"))
    # print(result.decode("gbk"))
    # file.write(str(result) + ‘\n‘)
file.close()

 

Python获取软件安装列表

原文:https://www.cnblogs.com/LoganChen/p/14074380.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!