python 程序列表

用 python  通过读取注册表来获取机器安装的程序列表,包括,软件名称,版本号,安装日期等

# -*- coding: UTF8 -*-
import _winreg
import os
import CommMethod

1、

'''获取SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths下的程序列表'''
def GetAppPathsRegeditInfo(list):
  keyPath = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
  key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyPath, 0, _winreg.KEY_ALL_ACCESS)
  listKeys = _winreg.QueryInfoKey(key)
  for i in xrange(0,listKeys[0]-1):
  key_name_list =_winreg.EnumKey(key, i)
  each_key_path = keyPath + '\\' + key_name_list
  try:
    each_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, each_key_path, 0, _winreg.KEY_READ)
    fpath,REG_SZ = _winreg.QueryValueEx(each_key, "")
    fInfo = CommMethod.getFileInfo(fpath)
    list.append(fInfo)
  except:
    continue

2、

  ''''获取SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall下的程序列表'''
    def GetUninstallRegeditInfo(list):
      keyPath = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
      key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyPath, 0, _winreg.KEY_ALL_ACCESS)
      for i in xrange(0,_winreg.QueryInfoKey(key)[0]-1):
        key_name_list =_winreg.EnumKey(key, i)
        each_key_path = keyPath+'\\'+key_name_list
        each_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, each_key_path, 0, _winreg.KEY_ALL_ACCESS)
        try:
          DisplayName, REG_SZ = _winreg.QueryValueEx(each_key, "DisplayName")
          #DisplayName = DisplayName.encode('utf-8')
          DisplayVersion, REG_SZ = _winreg.QueryValueEx(each_key, "DisplayVersion")
          InstallDate, REG_SZ = _winreg.QueryValueEx(each_key, "InstallDate")
          if (len(DisplayName)>0 and len(DisplayVersion)>0 and len(InstallDate)>0):
            fInfo = CommMethod.SoftwareInfo(DisplayName,InstallDate,DisplayVersion)
            list.append(fInfo)
        except WindowsError:
          pass

上一篇:IBM X3650 M5服务器RAID阵列设置


下一篇:服务器RAID配置全程与RAID基础知识