How do I programmatically kill a process running in Windows XP Pro that has gotten hung up?
Somebody suggested the taskkill command, as in
taskkill /f /t /im badprogram.exe
and I have been using this but it only sometimes kills the process.
Currently I am trying invoking the taskkill command or the simpler tskill command, with a variety of switches, and waits of 1 or 3 seconds between them, a total of 14 invocations. I’ll see if that works tonight. It can take hours for this whole setup to stop running.
I have observed that task manager will show a process called badprogram.exe running, and if I open a Run dialog and type taskkill /f /im badprogram.exe into it, sometimes badprogram will stop, but often it will not.
I really want to do this by passing a command to the OS from another app which is among other things acting as a watchdog to see if the bad program has stalled. This other app invokes badprogram and collects its output when written, but also watches the clock and tries to pull the plug on badprogram when it hangs. Making this work reliably is the problem.
One last question - how do I know what “image name” to include in the command? One reference points out that an image name is not the same as the name of the executable file, but it doesn’t say what else it is, and their example made it seem like the difference could be whether you tack the .exe onto the end. What is the image name of a process, if it is something other than the full filename of its executable?
Thanks!
If you really want to do this programmatically, then you want to look into the EnumProcesses and TerminateProcess APIs. EnumProcesses will let you go through the list of running processes until you find the one that is the executable you’re looking for, and then TerminateProcess will kill it unceremoniously.
You can even programmatically figure out if an app is hung by sending it a null message with SendMessageTimeout and specifying the correct fuFlags parameter.
My setup ran for about 12 hours before I shut it down myself, with dozens of hangs that it worked around. The version I was trying sends three taskills with different switches and one tskill, and one second pauses spaced around and between them. If this keeps working I might stay with it.
>There is plenty of programs out there that let you view the process and what they do and kill them. WinXP Manager will let you you do this.
You mean, I can execute something automatically to do this, without personally interacting with the system?
>If you really want to do this programmatically, then you want to look into the EnumProcesses and TerminateProcess APIs.
These are actually calls to the API, and not literally APIs themselves, right? So I would have to wrap them in a program that can make API calls? The program I am controlling things with now can pass OS command line calls, but I don’t know if it can make calls to the API.
PSKill looks interesting. Do I download it free or buy it?
Also, anybody know exactly how “image name” is related to the filename of the executable or to something else?