import os import subprocess # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_install(dir, args): os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) import time time.sleep(30) task=os.popen('Tasklist |Findstr "DuplicateFileFinder"').read() task=task.split() kill=os.popen("Taskkill /IM "+task[0]+" /F").read() print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_uninstall(dir, args): os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_update(dir, args): #It uninstalls the older version which will match with the registry unins=["Auslogics Duplicate File Finder"] import re import _winreg import time try: task=os.popen('Tasklist |Findstr "DuplicateFileFinder"').read() task=task.split() kill=os.popen("Taskkill /IM "+task[0]+" /F").read() time.sleep(10) except: time.sleep(5) blacklist=[] for i in unins: blacklist.append(i) print blacklist if 'PROGRAMFILES(X86)' in os.environ.keys(): uninstallkey='SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall' reg_list=[(_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_WOW64_32KEY | _winreg.KEY_ALL_ACCESS), (_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_WOW64_64KEY | _winreg.KEY_ALL_ACCESS), (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_WOW64_32KEY | _winreg.KEY_ALL_ACCESS), (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_WOW64_64KEY | _winreg.KEY_ALL_ACCESS)] else: uninstallkey='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall' reg_list=[(_winreg.HKEY_LOCAL_MACHINE,uninstallkey,_winreg.KEY_READ,_winreg.KEY_ALL_ACCESS), (_winreg.HKEY_CURRENT_USER,uninstallkey,_winreg.KEY_READ,_winreg.KEY_ALL_ACCESS)] strun=[] list=[] for i in reg_list: reg_key=i[0] sub_key=i[1] Value=i[2] reg =_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, i[1], 0, i[2]) i=0 while True: try: key_value=_winreg.EnumKey(reg,i) path=os.path.join(sub_key,key_value) Hkey=_winreg.OpenKey(reg_key,path,0,Value) try: key,dis_name=_winreg.QueryValueEx(Hkey,'DisplayName') inlist=[key.strip(), path, sub_key] list.append(inlist) except: pass i+=1 except: break for c in list: for i in range(0,len(blacklist)): if blacklist[i] in c[0]: try: RawKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, c[1],0,Value) (value, type) = _winreg.QueryValueEx(RawKey,"UninstallString") strun.append(value) Uninstr=re.findall('".*"',value) unin_str=''.join(Uninstr) command=unin_str+" /SILENT" unarglist= command.splitlines(True) unarglist2= ''.join(unarglist) print unarglist2 try: subprocess.check_call(unarglist2) print blacklist[i] +' older Version are removed' except subprocess.CalledProcessError as e: print blacklist[i] +' older Version does not exist, uninstaller returncode:' + str(e.returncode); except: pass time.sleep(60) os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) import time time.sleep(20) task=os.popen('Tasklist |Findstr "DuplicateFileFinder"').read() task=task.split() kill=os.popen("Taskkill /IM "+task[0]+" /F").read() print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'