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.
Another way is to use notepad:
First create 2 command prompt executables which end with “.BAT”
In the first one put these commands:
taskkill -f /im (process name with .EXE in the end)
Then put it to drive root.
The other one:
call (drive letter)\command.bat
Thanks a lot for the tips, Paul. Your approach (lets call it batch commands) works just fine 🙂
Thanks, but i forgot the last thing: If your computer is old and laggy just like mine, in the second one after command.bat write -high