Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/usr/bin/python2
- import win32api
- import win32con
- import os
- import glob
- def GetProductNameByProductGUID(gstr):
- rpath = r"SOFTWARE\Classes\Installer\Products\%s" % gstr
- try:
- hkey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, rpath, 0, win32con.KEY_READ)
- name = win32api.RegQueryValueEx(hkey, "ProductName")
- win32api.RegCloseKey(hkey)
- if name is not None:
- return name[0]
- except:
- print "!"
- pass
- def GetProductNameByPatchGUID(gstr):
- # 0x100 은 Win64 에서 Win32 프로세스가 Win64 Registry 에 접근하기 위한 것
- rhkey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products", 0, win32con.KEY_READ | 0x100)
- subkeys = win32api.RegEnumKeyEx(rhkey)
- for key in subkeys:
- try:
- hkey = win32api.RegOpenKeyEx(rhkey, "%s\\Patches" % key[0], 0, win32con.KEY_READ | 0x100)
- subkeys2 = win32api.RegEnumKeyEx(hkey)
- for subkey in subkeys2:
- if (subkey[0] == gstr):
- hkey2 = win32api.RegOpenKeyEx(hkey, subkey[0], 0, win32con.KEY_READ | 0x100)
- name = win32api.RegQueryValueEx(hkey2, "DisplayName")
- hkey3 = win32api.RegOpenKeyEx(rhkey, "%s\\InstallProperties" % key[0], 0, win32con.KEY_READ | 0x100)
- pname = win32api.RegQueryValueEx(hkey3, "DisplayName")
- return "[%s]%s" % (pname[0], name[0])
- win32api.RegCloseKey(hkey)
- except:
- continue
- def GetProductNameByMsiFile(file):
- rhkey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products", 0, win32con.KEY_READ | 0x100)
- subkeys = win32api.RegEnumKeyEx(rhkey)
- for key in subkeys:
- try:
- hkey = win32api.RegOpenKeyEx(rhkey, "%s\\InstallProperties" % key[0], 0, win32con.KEY_READ | 0x100)
- package = win32api.RegQueryValueEx(hkey, "LocalPackage")
- if package is not None and package[0].lower() == file.lower():
- name = win32api.RegQueryValueEx(hkey, "DisplayName")
- if name is not None:
- win32api.RegCloseKey(hkey)
- return name[0]
- win32api.RegCloseKey(hkey)
- except:
- continue
- def GetProductNameByMspFile(file):
- rhkey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Patches", 0, win32con.KEY_READ | 0x100)
- subkeys = win32api.RegEnumKeyEx(rhkey)
- for key in subkeys:
- try:
- hkey = win32api.RegOpenKeyEx(rhkey, "%s" % key[0], 0, win32con.KEY_READ | 0x100)
- package = win32api.RegQueryValueEx(hkey, "LocalPackage")
- if package is not None and package[0].lower() == file.lower():
- return GetProductNameByPatchGUID(key[0])
- win32api.RegCloseKey(hkey)
- except:
- continue
- def GetDirectorySize(path):
- total = 0
- for root, dirs, files in os.walk(path):
- for file in files:
- try:
- total += os.path.getsize(os.path.join(root, file))
- except:
- pass
- return total
- def ViewInstallerFile():
- print "file\tname\tsize"
- rootDir = r"C:\Windows\Installer"
- for path in glob.glob(os.path.join(rootDir, "*")):
- if os.path.isfile(path):
- file = os.path.split(path)[1]
- ext = os.path.splitext(file)[1].lower()
- if ext == ".msi":
- name = GetProductNameByMsiFile(path)
- size = os.path.getsize(path)
- print "%s\t%s\t%d" % (file, name, size)
- if ext == ".msp":
- name = GetProductNameByMspFile(path)
- size = os.path.getsize(path)
- print "%s\t%s\t%d" % (file, name, size)
- def ViewPatchCache():
- print "dir\tname\tsize"
- rootDir = r"C:\Windows\Installer\$PatchCache$\Managed"
- for dir in os.listdir(rootDir):
- name = GetProductNameByProductGUID(dir)
- size = GetDirectorySize(os.path.join(rootDir, dir))
- print "%s\t%s\t%d" % (dir, name, size)
- def ViewAll():
- print "***** Installer *****"
- ViewInstallerFile()
- print
- print "***** Installer\$PatchCache$\Managed *****"
- ViewPatchCache()
- print
- ViewAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement