import os import subprocess # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_install(dir, args): import os import time if 'PROGRAMFILES(X86)' in os.environ.keys(): uninstallkey='SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall' os.popen('REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\N360').read() else: uninstallkey='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall' os.popen('REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\N360').read() os.chdir(dir) argslist = args.split() try: subprocess.call(argslist) time.sleep(10) try: tasklist1=os.popen('Tasklist |findstr "ADE"').read() task1=tasklist.split() print task1 stp='Taskkill /IM '+task[0]+' /F' kill=os.popen(stp).read() except: pass 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=["Adobe Digital Editions"] import re import _winreg import time ## from _winreg import * blacklist=[] for i in unins: blacklist.append(i) if 'PROGRAMFILES(X86)' in os.environ.keys(): uninstallkey='SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall' os.popen('REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\N360').read() 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' os.popen('REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\N360').read() 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+" /S /NORESTART" unarglist= command.splitlines(True) unarglist2= ''.join(unarglist) print unarglist2 try: try: tasklist1=os.popen('Tasklist |findstr "rmm"').read() task1=tasklist.split() stp='Taskkill /IM '+task[0]+' /F' kill=os.popen(stp).read() tasklist2=os.popen('Tasklist |findstr "ADE"').read() task2=tasklist2.split() stp2='Taskkill /IM '+task[0]+' /F' kill2=os.popen(stp2).read() except: pass 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 os.chdir(dir) argslist = args.split() try: subprocess.call(argslist) time.sleep(30) try: tasklist1=os.popen('Tasklist |findstr "rmm"').read() task1=tasklist.split() stp='Taskkill /IM '+task[0]+' /F' kill=os.popen(stp).read() tasklist2=os.popen('Tasklist |findstr "ADE"').read() task2=tasklist2.split() stp2='Taskkill /IM '+task[0]+' /F' kill2=os.popen(stp2).read() except: pass print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'