-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
148 lines (127 loc) · 5.08 KB
/
Main.py
File metadata and controls
148 lines (127 loc) · 5.08 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import psutil
import winreg
import ctypes
import sys
def is_admin():
"""Check if the script is running with administrative privileges."""
try:
return ctypes.windll.shell32.IsUserAnAdmin() != 0
except Exception as e:
print(f"Error checking admin status: {e}")
return False
def run_as_admin():
"""Relaunch the script with administrative privileges."""
if is_admin():
return
script = sys.argv[0]
try:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
except Exception as e:
print(f"Error relaunching script as admin: {e}")
sys.exit()
def is_process_running(process_name):
"""Checks if a process is running by its name."""
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'] == process_name:
return True
return False
def terminate_process(process_name):
"""Terminates a process by its name."""
try:
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'] == process_name:
p = psutil.Process(proc.info['pid'])
p.terminate()
p.wait() # Wait for the process to terminate
print(f"Terminated process: {process_name}")
return True
except (psutil.NoSuchProcess, psutil.AccessDenied) as e:
print(f"Error terminating process {process_name}: {e}")
return False
def is_autostart_disabled(program_name):
"""Checks if the autostart program is already disabled."""
paths = [
r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
r"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"
]
for path in paths:
try:
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ)
try:
value, _ = winreg.QueryValueEx(registry_key, program_name)
if value:
return False # Entry exists, so it's not disabled
except FileNotFoundError:
pass
finally:
winreg.CloseKey(registry_key)
except PermissionError:
print("Permission error: Run this script as an administrator.")
return False
except Exception as e:
print(f"Error checking autostart: {e}")
return False
return True # Entry does not exist, so it's disabled
def disable_autostart(program_name):
"""Disables an autostart program by removing its registry entry."""
paths = [
r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
r"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"
]
for path in paths:
try:
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_WRITE)
try:
winreg.DeleteValue(registry_key, program_name)
print(f"Disabled autostart for: {program_name}")
winreg.CloseKey(registry_key)
return True
except FileNotFoundError:
continue
finally:
winreg.CloseKey(registry_key)
except PermissionError:
print("Permission error: Run this script as an administrator.")
return False
except Exception as e:
print(f"Error disabling autostart: {e}")
return False
print(f"Registry entry for {program_name} not found.")
return False
def main():
"""Main function to handle the script execution."""
run_as_admin() # Ensure the script is running with admin privileges
print("Starting the process termination and registry modification script...\n")
# Check if processes are running
processes_running = {
"RiotClientServices.exe": is_process_running("RiotClientServices.exe"),
"RiotClientCrashHandler.exe": is_process_running("RiotClientCrashHandler.exe"),
"vgtray.exe": is_process_running("vgtray.exe")
}
# Print process status
for proc, running in processes_running.items():
status = "running" if running else "not running"
print(f"{proc} is {status}.")
if any(processes_running.values()):
print("\nTerminating processes...")
# Terminate the processes
processes_terminated = all([
terminate_process("RiotClientServices.exe"),
terminate_process("RiotClientCrashHandler.exe"),
terminate_process("vgtray.exe")
])
else:
print("No specified processes are running.")
processes_terminated = True
# Check if autostart is already disabled
autostart_disabled = is_autostart_disabled("Riot Vanguard")
if not autostart_disabled:
print("\nDisabling autostart...")
autostart_disabled = disable_autostart("Riot Vanguard")
if processes_terminated and autostart_disabled:
print("\nAll tasks completed successfully.")
else:
print("\nSome tasks encountered errors.")
input("Press Enter to close...")
if __name__ == "__main__":
main()