MCPcopy Create free account
hub / github.com/MCSLTeam/MCSL2 / set_start_on_startup

Function set_start_on_startup

MCSL2Lib/ProgramControllers/startupController.py:52–66  ·  view source on GitHub ↗
(enabled: bool)

Source from the content-addressed store, hash-verified

50
51
52def 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

Callers 3

__init__Method · 0.90

Calls 2

_get_app_nameFunction · 0.85
_build_launch_commandFunction · 0.85

Tested by

no test coverage detected