"e-Ricc" <rk****@hotmail.comwrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
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
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.