I needed a way to kill a windows process/task programatically and wondered what could be the best way to do so. By process/task, I mean an entry that can be found under “task manager” (through CTRL-ALT-DEL). Don’t confuse that with services which are different things that you can see by running services.msc.
How To Kill Windows Tasks and Processes
It’s easy with a windows builtin executable known as taskkill. Open up a windows command prompt and type taskkill /? to see what you can do with it. For example, if you want to close notepad.exe, you can type in
taskkill /F /IM notepad.exe
Getting this to run in a .net application is quite simple as well. The following example is written in VB.NET.
Dim process As System.Diagnostics.Process = Nothing
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.FileName = “taskkill.exe”
psi.Arguments = “/F /IM notepad.exe”
process = System.Diagnostics.Process.Start(psi)
*I’ve heard that taskkill.exe isn’t delivered with Windows 2000. Can someone confirm that? I’ve been able to find taskkill.exe in windows 2003, XP, Vista and 7.