码迷,mamicode.com
首页 > 编程语言 > 详细

python 程序列表

时间:2016-06-20 12:37:03      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:

用 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

python 程序列表

标签:

原文地址:http://www.cnblogs.com/shaosks/p/5599980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!