I use the following commands to kill a task in Task Manager.

os.system("taskkill /f /im  " + ProgName)

It works fine for most tasks but I found one that it fails to kill.


I think its because it has more than one period in the name but I am not sure. I tried multiple variations of the name.


Is there a way to kill all tasks that begin with a string (e.x. CefSharp*) using python3?

P.S. this is my very first question on the site, please forgive my ignorance of the subject and any mistakes in tagging or phrasing.

1 Answers

Martin Evans On Best Solutions

The Windows taskkill tool does take wildcards, so it should be possible to test:

os.system("taskkill /F /IM CefSharp* /T")

/T is used to kill all child processes.

Or as follows:

ProgName = "CefSharp*"
os.system(f"taskkill /F /IM {ProgName} /T")