import os import subprocess import shutil import time import glob import sys try: import winreg except ImportError: import _winreg as winreg def safe_rmtree(path): try: if os.path.exists(path): # First try Python shutil shutil.rmtree(path, ignore_errors=True) time.sleep(1) # If still exists, force delete via cmd if os.path.exists(path): subprocess.call( 'cmd /c rd /s /q "%s"' % path, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) time.sleep(1) except Exception: pass def safe_delete(pattern): try: for f in glob.glob(pattern): try: os.remove(f) except Exception: pass except Exception: pass def delete_reg_tree(root, path): try: key = winreg.OpenKey(root, path, 0, winreg.KEY_ALL_ACCESS) except Exception: return while True: try: sub = winreg.EnumKey(key, 0) delete_reg_tree(root, path + "\\" + sub) except Exception: break try: winreg.CloseKey(key) except Exception: pass try: winreg.DeleteKey(root, path) except Exception: pass def remove_wise_reg_entries(): locations = [ r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", ] for root in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER): for base in locations: keys_to_delete = [] try: key = winreg.OpenKey(root, base) except Exception: continue i = 0 while True: try: sub = winreg.EnumKey(key, i) i += 1 except Exception: break try: sk = winreg.OpenKey(root, base + "\\" + sub) try: name, _ = winreg.QueryValueEx(sk, "DisplayName") if "Wise Registry Cleaner" in name: keys_to_delete.append(sub) except Exception: pass winreg.CloseKey(sk) except Exception: pass try: winreg.CloseKey(key) except Exception: pass # Delete after closing parent key to avoid access issues for sub in keys_to_delete: delete_reg_tree(root, base + "\\" + sub) def wise_exe_exists(): exes = [ r"C:\Program Files\Wise\Wise Registry Cleaner\WiseRegistryCleaner.exe", r"C:\Program Files (x86)\Wise\Wise Registry Cleaner\WiseRegistryCleaner.exe", ] return any(os.path.exists(e) for e in exes) def wise_folder_exists(): folders = [ r"C:\Program Files\Wise\Wise Registry Cleaner", r"C:\Program Files (x86)\Wise\Wise Registry Cleaner", ] return any(os.path.exists(f) for f in folders) def wise_registry_exists(): locations = [ r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", ] for root in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER): for base in locations: try: key = winreg.OpenKey(root, base) except Exception: continue i = 0 while True: try: sub = winreg.EnumKey(key, i) i += 1 except Exception: break try: sk = winreg.OpenKey(root, base + "\\" + sub) try: name, _ = winreg.QueryValueEx(sk, "DisplayName") if "Wise Registry Cleaner" in name: winreg.CloseKey(sk) winreg.CloseKey(key) return True except Exception: pass winreg.CloseKey(sk) except Exception: pass try: winreg.CloseKey(key) except Exception: pass return False def kill_processes(): processes = [ "WiseRegistryCleaner.exe", "WiseRegCleaner.exe", "unins000.exe", ] for p in processes: try: subprocess.call( 'taskkill /F /IM "%s"' % p, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) except Exception: pass def run_uninstaller(unins_path): try: cmd = '"%s" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' % unins_path proc = subprocess.Popen(cmd, shell=True) # Wait up to 120 seconds for uninstaller to finish for _ in range(60): if proc.poll() is not None: break time.sleep(2) else: try: proc.kill() except Exception: pass except Exception: pass def force_cleanup(): # Kill any remaining processes kill_processes() time.sleep(2) # Force delete folders safe_rmtree(r"C:\Program Files\Wise\Wise Registry Cleaner") safe_rmtree(r"C:\Program Files (x86)\Wise\Wise Registry Cleaner") # Clean up empty parent Wise folder for wise_dir in [r"C:\Program Files\Wise", r"C:\Program Files (x86)\Wise"]: try: if os.path.exists(wise_dir) and not os.listdir(wise_dir): os.rmdir(wise_dir) except Exception: pass # Remove shortcuts safe_delete(r"C:\Users\Public\Desktop\*Wise*.lnk") safe_delete(r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*Wise*.lnk") # Remove registry entries remove_wise_reg_entries() time.sleep(2) def spm_uninstall(dir, args): # Step 1: Kill running processes kill_processes() time.sleep(2) # Step 2: Run official uninstaller if it exists uninstallers = [ r"C:\Program Files\Wise\Wise Registry Cleaner\unins000.exe", r"C:\Program Files (x86)\Wise\Wise Registry Cleaner\unins000.exe", ] for unins in uninstallers: if os.path.exists(unins): run_uninstaller(unins) # Step 3: Force cleanup regardless of uninstaller result force_cleanup() # Step 4: Poll up to 60 seconds to confirm removal for i in range(30): exe_gone = not wise_exe_exists() reg_gone = not wise_registry_exists() if exe_gone and reg_gone: print("retcode0retcode") return # Keep retrying registry cleanup on each poll if not reg_gone: remove_wise_reg_entries() # Keep retrying folder cleanup on each poll if not exe_gone: safe_rmtree(r"C:\Program Files\Wise\Wise Registry Cleaner") safe_rmtree(r"C:\Program Files (x86)\Wise\Wise Registry Cleaner") time.sleep(2) # Step 5: Final check — exe and registry both gone = success # (leftover empty folders are acceptable) if not wise_exe_exists() and not wise_registry_exists(): print("retcode0retcode") else: print("retcode1retcode") def spm_install(dir, args): try: os.chdir(dir) subprocess.check_call(args, shell=True) print("retcode0retcode") except subprocess.CalledProcessError as e: print("retcode" + str(e.returncode) + "retcode") def spm_update(dir, args): try: os.chdir(dir) subprocess.check_call(args, shell=True) print("retcode0retcode") except subprocess.CalledProcessError as e: print("retcode" + str(e.returncode) + "retcode")