-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkillProcess.py
More file actions
43 lines (40 loc) · 1.45 KB
/
Copy pathkillProcess.py
File metadata and controls
43 lines (40 loc) · 1.45 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
import psutil
PROCESS_DICT = {
"Chrome": "chrome.exe",
"Edge": "msedge.exe",
"Firefox": "firefox.exe",
"Discord": "Discord.exe",
"Spotify": "Spotify.exe",
"VSCode": "Code.exe",
"Notepad": "notepad.exe",
"Explorer": "explorer.exe",
"Teams": "Teams.exe",
"Zoom": "Zoom.exe",
"Word": "WINWORD.EXE",
"Excel": "EXCEL.EXE",
"PowerPoint": "POWERPOINT.EXE",
"Steam": "steam.exe",
"WhatsApp": "WhatsApp.exe",
"Photoshop": "Photoshop.exe",
"Nvidia": "nvidia.exe"
}
def kill_process_by_name(app_name: str) -> str:
"""
Kills a known Windows process by its user-friendly application name.
Example input: 'Chrome' will attempt to kill 'chrome.exe'.
"""
target_name = PROCESS_DICT.get(app_name.strip().title())
if not target_name:
known_apps = ", ".join(PROCESS_DICT.keys())
return f"❌ Unknown application '{app_name}'. Known apps: {known_apps}"
killed = False
for proc in psutil.process_iter(['pid', 'name']):
try:
if proc.info['name'].lower() == target_name.lower():
proc.kill()
killed = True
except (psutil.NoSuchProcess, psutil.AccessDenied) as e:
print(f"Error killing process: {e}")
continue
return (f"✅ Successfully terminated '{app_name}'." if killed
else f"⚠️ '{app_name}' is not running or couldn't be terminated.")