The last few days, I have been looking into a solution to kill a process in c/c++ – but not just any process, a ScreenSaver running while the computer is locked. Most examples on MSDN and such terminiate processes by sending close messages to them, and 99% of the time that works. It even works for ScreenSavers that are running while the computer is locked. Thing is, I didnt want to bundle kill.exe that comes on the Windows NT Resource kit. Off to search google, pskill by sysinternals works too, but again with the bundling. Search the net some more, I found a link to the kill.exe source code from MSDN. The big difference in this code compared to all other kill examples, is this
//
// Obtain the ability to manipulate other processes
//
EnableDebugPriv();
That opened the door for the kill.exe to stop a process when the computer was locked 100% of the time. Im sure there is some long explination dealing with user mode and kernel mode code, maybe someone can comment on and shed some more light on the subject. I have attached the source code that I found here just in case the site it was on goes down. Well, in the end, we ended up getting the program to kill the process while the computer was locked, so it worked out well 🙂
6 replies on “Kill.exe and EnableDebugPriv()”
Couldn’t you have just used OpenProcess, then TerminateProcess to do the job? Debugger privs are a strange thing (and I think they can be disabled via the registry as well, IIRC).
LikeLike
Well, tried that and it didnt work when locked and trying to kill the saver…weird I know
LikeLike
Hmm, well, depending on the version of the OS, not quite so weird. The screensaver runs on its own desktop, so I think you have to do something special in that case. But you’ve got a working solution, which is a good deal (though I don’t think I want to know what it is you’re trying to accomplish).
LikeLike
Hi Steve,
Do you use this script to kill screensavers running on remote machines?
I have been looking for a way to do so without having to list the PID and then kill it via the pstools. The screensaver can vary as well but they are all .scr
If you know of anyway or can be of help, please email me!
Peace!
LikeLike
Hi,
What is the restriction in packaging kill.exe or pskill.exe
Thanks
Anu
LikeLike
And also from where did you get this source code ?
LikeLike