"""Helper to register ICEYOU to run at Windows startup.""" import os import sys import winreg from pathlib import Path def add_to_startup(app_name: str = "ICEYOU") -> bool: """Add the current script to Windows startup via registry.""" try: exe_path = sys.executable script_path = str(Path(__file__).parent.parent.parent / "main.py") command = f'"{exe_path}" "{script_path}"' key = winreg.OpenKey( winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_SET_VALUE ) winreg.SetValueEx(key, app_name, 0, winreg.REG_SZ, command) winreg.CloseKey(key) print(f"Added to startup: {command}") return True except Exception as e: print(f"Failed to add to startup: {e}") return False def remove_from_startup(app_name: str = "ICEYOU") -> bool: try: key = winreg.OpenKey( winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_SET_VALUE ) winreg.DeleteValue(key, app_name) winreg.CloseKey(key) print("Removed from startup.") return True except FileNotFoundError: print("Not registered.") return False except Exception as e: print(f"Error: {e}") return False if __name__ == "__main__": add_to_startup()