-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckSystem.py
More file actions
91 lines (71 loc) · 2.76 KB
/
checkSystem.py
File metadata and controls
91 lines (71 loc) · 2.76 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import platform
import subprocess
import config
import winreg
import os
import ctypes
def checkWindowsVersion() -> int:
"""
Check windows version and return number
:rtype: int
"""
if(platform.system().lower() == "windows"):
return int(platform.release())
def is_admin() -> bool:
try:
return os.getuid() == 0
except AttributeError:
return ctypes.windll.shell32.IsUserAnAdmin() != 0
def stopUpdateService(service_name:str) -> None:
try:
if is_admin():
result = subprocess.run(['sc', 'stop', service_name], capture_output=True, text=True, check=False)
if(result.returncode == 0):
config.debug_success('The service is stopped')
elif(result.returncode == 1062):
config.debug_warning('The service is\'t stopped. The service may have been stopped earlier')
else:
config.debug_error(f'Error with the service stop, code: {result.returncode}')
print(result.stderr.strip())
else:
config.debug_warning('Run the application as an administrator!')
except Exception as e:
config.debug_error(e)
def changeServiceStartType(service_name:str, start_type:str) -> None:
"""
Docstring for changeServiceStartType
:param service_name: Service name for change start type
:type service_name: str
:param start_type: auto, disabled, demand
:type start_type: str
"""
try:
if is_admin():
result = subprocess.run(['sc', 'config', service_name, 'start=', start_type], capture_output=True, text=True, check=False)
if(result.returncode == 0):
config.debug_success(f'The service start type changed on: {start_type}')
else:
config.debug_error(f'Error with the service stop, code: {result.returncode}')
print(result.stderr.strip())
else:
config.debug_warning('Run the application as an administrator!')
except Exception as e:
config.debug_error(e)
def regeditDisableUpdate(key_name:str, value:str, key_type:winreg.HKEYType, path:str) -> None:
"""
Docstring for regeditDisableUpdate
:param key_name: Name for key
:type key_name: str
:param value: Key value
:type value: str
:param key_type: Key type (winreg.REG_SZ for example)
:type key_type: winreg.HKEYType
:param path: Path to put key
:type path: str
"""
try:
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, access=winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, key_name, 0, key_type, value)
config.debug_success('Registry was changed')
except Exception as e:
config.debug_error(e)