import os import subprocess import time import shutil import _winreg def delete_reg_key(root, path): try: _winreg.DeleteKey(root, path) except: pass def spm_uninstall(dir, args): try: # Kill running processes subprocess.call('taskkill /F /IM WiseRegistryCleaner.exe', shell=True) subprocess.call('taskkill /F /IM WiseRegCleaner.exe', shell=True) subprocess.call('taskkill /F /IM unins000.exe', shell=True) time.sleep(5) uninstallers = [ r'C:\Program Files (x86)\Wise\Wise Registry Cleaner\unins000.exe', r'C:\Program Files\Wise\Wise Registry Cleaner\unins000.exe' ] # Run uninstallers for uninstaller in uninstallers: if os.path.exists(uninstaller): cmd = '"' + uninstaller + '" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART' subprocess.Popen(cmd, shell=True) time.sleep(40) subprocess.call('taskkill /F /IM unins000.exe', shell=True) # Remove folders remove_paths = [ r'C:\Program Files (x86)\Wise\Wise Registry Cleaner', r'C:\Program Files\Wise\Wise Registry Cleaner', r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Wise Registry Cleaner', r'C:\Users\Public\Desktop\Wise Registry Cleaner.lnk' ] for path in remove_paths: try: if os.path.isdir(path): shutil.rmtree(path, ignore_errors=True) elif os.path.isfile(path): os.remove(path) except: pass # Remove uninstall registry keys delete_reg_key( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Wise Registry Cleaner_is1" ) delete_reg_key( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Wise Registry Cleaner_is1" ) time.sleep(5) # Final verification failed = False verify_paths = [ r'C:\Program Files (x86)\Wise\Wise Registry Cleaner', r'C:\Program Files\Wise\Wise Registry Cleaner' ] for path in verify_paths: if os.path.exists(path): failed = True if failed: raise Exception('Clean Uninstall Failed') print 'Wise Registry Cleaner fully removed' print 'retcode0retcode' except Exception as e: print str(e) print 'retcode1retcode'