1.python獲取windows軟件安裝列表

   windows系統會在兩個地方記錄軟件列表:

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')


結果如下:

[root@netserver temp]# cat op-tanjun3.txt | egrep -v "Microsoft|NVIDIA|Intel"
360安全衛士
64 Bit HP CIO Components Installer
Adobe AIR
Adobe Flash Player 21 NPAPI
Adobe Flash Player 21 PPAPI
Adobe Reader XI (11.0.15) - Chinese Simplified
Java 7 Update 79
Java 7 Update 79 (64-bit)
Java Auto Updater
KeyPass
Pidgin
PyQt GPL v4.10.2 for Python v2.7 (x64)
Python 2.7.3 (64-bit)
Realtek High Definition Audio Driver
Remote Desktop Organizer
Shotgun Integration
Sublime Text 2.0.2
Synology Assistant (remove only)
TeamViewer 11
VMware Workstation
VMware vSphere Client 6.0
WinRAR 5.30 (64-位)
Xshell 5
bl
hppLaserJetService
ph
tools-freebsd
tools-linux
tools-netware
tools-solaris
tools-winPre2k
tools-windows
搜狗拼音輸入法 7.9正式版
騰訊QQ
英特爾? 芯片組設備軟件


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章