Dido Sevilla wrote:
> On 9/23/05, Daniel Berger <djberg96 / gmail.com> wrote:
> > You can't.  Using the "end process" button on the Task Manager calls
> > the TerminateProcess() function, which can't be trapped.  Read here for
> > more:
> >
> > http://blogs.msdn.com/oldnewthing/archive/2004/07/22/191123.aspx
> >
> > It's probably a good thing, too.  Imagine if you did this:
> >
> > trap("KILL"){ # Do nothing }
> >
> > How would you kill the process short of rebooting?
>
> Gee, so there's only a SIGKILL on Windows, and no equivalent of a
> SIGTERM? What if I want the process to try to do some cleanup before
> dying? This is something I do fairly often with my programs on
> GNU/Linux. Now if the cleanup is hosed, obviously I'd expect a kill -9
> to still work of course...

Well, drat, I *thought* the CreateRemoteThread + ExitProcess combo was
catchable, but I'm not so sure now.  It may require a custom handler,
but I'd have to research further.

Also, take a look at this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminating_a_process.asp

That article suggests a RegisterWindowMessage + BroadcastSystemMessage
approach, though I haven't tried it.

Regards,

Dan