-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gd
41 lines (32 loc) · 1.08 KB
/
main.gd
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
extends Node2D
onready var _endTaskButton = $EndTaskButton
onready var _taskNameLineEdit = $TaskNameLineEdit
func _ready() -> void:
pass
# Finds all tasks with the specified image name
# which is the executable name as it shows up in task manager.
func TerminateProcess(taskName):
var output = []
var error = OS.execute("tasklist", ["/fi", "imagename eq " + taskName, "/fo", "csv"], true, output)
if error == 1:
print("Failed to execute tasklist command!")
return
var taskListData : Array = output[0].split("\n", false)
# Remove the headers
taskListData.remove(0)
if taskListData.empty():
print("Did not find a matching task to terminate.")
return
for line in taskListData:
var data = line.split(",")
var pid = data[1]
error = OS.execute("taskkill", ["/f", "/pid", pid], true)
if error == 1:
print("Failed to end task to pid: " + pid)
else:
print("Successfully ended task to pid: " + pid)
func _on_Button_pressed() -> void:
if _taskNameLineEdit.text == "":
OS.alert("Yo! Need to provide a task name first!")
return
TerminateProcess(_taskNameLineEdit.text)