Hi guys!
Im trying to detect when a user "kills" my c# app using windows task
manager, i've tried with the form events _closing and _closed managing
for example putting an if inside to detect it:
if (e.CloseReason == CloseReason.TaskManagerClosing)
{
MessageBox.Show("from task manager");
}
but it doesn´t works, any idea?
Regards
Ricc
Alvin Bruney [MVP] - 11 Oct 2007 02:19 GMT
I haven't found a way yet to catch this type of scenario, maybe others have.
As a substitute, it is common to write a watch dog application that monitors
for the existence of the exe and starts it if it does not detect it running.

Signature
Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$24.99
> Hi guys!
>
[quoted text clipped - 11 lines]
> Regards
> Ricc
Michael Nemtsev, MVP - 11 Oct 2007 10:49 GMT
Hello e-Ricc,
u need to inject dll into the taskmanager, hooking the TerminateProcess in
Kernel32
and such u can add your custom code
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
e> Hi guys!
e>
e> Im trying to detect when a user "kills" my c# app using windows task
e> manager, i've tried with the form events _closing and _closed
e> managing for example putting an if inside to detect it:
e>
e> if (e.CloseReason == CloseReason.TaskManagerClosing)
e> {
e> MessageBox.Show("from task manager");
e> }
e> but it doesn?t works, any idea?
e>
e> Regards
e> Ricc
Ben Voigt [C++ MVP] - 15 Oct 2007 15:25 GMT
<Michael Nemtsev>; "MVP" <nemtsev@msn.com> wrote in message
news:3d9fba1a10a298c9da57078aeb60@msnews.microsoft.com...
> Hello e-Ricc,
>
> u need to inject dll into the taskmanager, hooking the TerminateProcess in
> Kernel32
> and such u can add your custom code
Would work I suspect, but no user would ever voluntarily use software that
does such a thing.
> ---
> WBR, Michael Nemtsev [.NET/C# MVP] :: blog:
[quoted text clipped - 13 lines]
> e> e> Regards
> e> Ricc
e-Ricc - 15 Oct 2007 17:10 GMT
Oki doki!
let me look for info, thanks!!
Regards
e-Ricc
> <Michael Nemtsev>; "MVP" <nemtsev@msn.com> wrote in message
> news:3d9fba1a10a298c9da57078aeb60@msnews.microsoft.com...
[quoted text clipped - 24 lines]
>> e> e> Regards
>> e> Ricc
Willy Denoyette [MVP] - 11 Oct 2007 12:06 GMT
> Hi guys!
>
[quoted text clipped - 11 lines]
> Regards
> Ricc
This event (TaskManagerClosing) is raised when the "Task" is terminated, not
when the "Process" is terminated, the latter stops the process cold, no
events are raised, so there is nothing you can do from within the
application itself.
One solution for this is to Remove Taskman from the taskbar using Group
Policy Management (Local Computer Policy), sure this isn't of any help if
the user has other means to kill a running process.
To watch process termination events, you can run a watchdog (needs
administrative privileges!) which listens for WMI "Win32_ProcessStopTrace"
events using System.Management 's ManagementEventWatcher.
Willy.