0

I've got python to terminate the most of the processes with os.kill but it doesen't really work properly on windows.

I've tried many ways of terminating the processes. The first one was to get all processes with wmi.WMI.Win32_Process() which was incredibly slow. So I changed that to this:

def processes():
    subp = subprocess.Popen(["tasklist", "/FO", "CSV", "/NH"], stdout=subprocess.PIPE)
    processes_from_command = subp.stdout.read().decode("ISO-8859-1")
    subp.terminate()

    for row in processes_from_command.split("\n")[:-1]:
        yield int(row.split(",")[1].replace("\"", ""))

That gives me a generator object which gives me process ids of all running processes fast. Then I killed them with os.kill. But still some processes didn't want to get terminated like explorer.exe.

How can I kill the explorer.exe process?. The top answer there suggested to use taskkill which works perfect except that it's very slow. Is there any way I can run the taskkill on all pids in the processes() asynchronous? If not how would I else do to terminate all processes fast.

Robiot
  • 98
  • 10

1 Answers1

0

TASKKILL /PID 1230 /PID 1241 /PID 1253 /T ? maybe?

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179