-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
windows.py
58 lines (50 loc) · 1.39 KB
/
windows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""System Bridge: Autostart Windows"""
import os
import platform
import sys
def autostart_windows_disable():
"""Disable autostart for Windows"""
if platform.system() != "Windows":
return
# pylint: disable=import-error, import-outside-toplevel
from winreg import HKEY_CURRENT_USER, KEY_ALL_ACCESS, CloseKey, DeleteValue, OpenKey
try:
key = OpenKey(
HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run",
reserved=0,
access=KEY_ALL_ACCESS,
)
if key is None:
return
DeleteValue(key, "systembridgebackend")
CloseKey(key)
except OSError:
pass
def autostart_windows_enable():
"""Enable autostart for Windows"""
if platform.system() != "Windows":
return
# pylint: disable=import-error, import-outside-toplevel
from winreg import (
HKEY_CURRENT_USER,
KEY_ALL_ACCESS,
REG_SZ,
CloseKey,
OpenKey,
SetValueEx,
)
key = OpenKey(
HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run",
reserved=0,
access=KEY_ALL_ACCESS,
)
SetValueEx(
key,
"systembridgebackend",
0,
REG_SZ,
f'"{os.path.join(os.path.dirname(sys.executable), "pythonw.exe")}" -m systembridgebackend --silent',
)
CloseKey(key)