- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckSystem.py
More file actions
Latest commit
91 lines (71 loc) · 2.76 KB
/
Copy pathcheckSystem.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
importplatform
importsubprocess
importconfig
importwinreg
importos
importctypes
defcheckWindowsVersion() ->int:
"""
Check windows version and return number
:rtype: int
"""
if(platform.system().lower() =="windows"):
returnint(platform.release())
defis_admin() ->bool:
try:
returnos.getuid() ==0
exceptAttributeError:
returnctypes.windll.shell32.IsUserAnAdmin() !=0
defstopUpdateService(service_name:str) ->None:
try:
ifis_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!')
exceptExceptionase:
config.debug_error(e)
defchangeServiceStartType(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:
ifis_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!')
exceptExceptionase:
config.debug_error(e)
defregeditDisableUpdate(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:
withwinreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, access=winreg.KEY_ALL_ACCESS) askey:
winreg.SetValueEx(key, key_name, 0, key_type, value)
config.debug_success('Registry was changed')
exceptExceptionase:
config.debug_error(e)