(enabled: bool)
| 50 | |
| 51 | |
| 52 | def set_start_on_startup(enabled: bool) -> None: |
| 53 | if system().lower() != "windows": |
| 54 | raise RuntimeError("当前系统暂不支持开机自启动") |
| 55 | import winreg |
| 56 | |
| 57 | name = _get_app_name() |
| 58 | key_path = r"Software\Microsoft\Windows\CurrentVersion\Run" |
| 59 | with winreg.CreateKey(winreg.HKEY_CURRENT_USER, key_path) as k: |
| 60 | if enabled: |
| 61 | winreg.SetValueEx(k, name, 0, winreg.REG_SZ, _build_launch_command()) |
| 62 | return |
| 63 | try: |
| 64 | winreg.DeleteValue(k, name) |
| 65 | except FileNotFoundError: |
| 66 | return |
no test coverage detected