FormClosing Event

  • Thread starter Thread starter DarxOman
  • Start date Start date
D

DarxOman

FormClosing Event doesn't Fire when I kill The app with the Task Manager!!
Any Ideas Why??

what I'm Trying to do here is I'm trying to Cancel the Form Closing by
setting the
e.cancel = True
But never get it to work when I kill the App with the Task manager.
 
Hi DarxOman,

Processes that are being killed using TaskManager will not fire any event in
the application and therefore cannot be cancelled, since they are simply
abruptly terminated.

If you seek to prevent your application from being terminated using
TaskManager you need to elevate the process privileges to something that the
logged on user is not allowed to terminate, like running as System.
 
thanx Morten

But would you explain more on How to "elevate the process privileges to
something that the logged on user is not allowed to terminate, like running
as System."
 
Hi,

I haven't tested this, but apparantly you are able to launch programs using
the system account (LocalSystem) by having a windows service running as
LocalSystem and make that service launch your program. This should prevent
even an administrator from terminating the app, although it wouldn't prevent
him from disabling the service and restarting the computer. If you need to
prevent even this you need to run windows in kiosk mode (which would prevent
task manager from being accessible as well).

I'm afraid I don't have any samples for how this is being done, but the
general idea is

Create a windows service that launches your application
Create an installer for the windows service that specifies LocalSystem as
the account it should run under (note this can be overruled during and after
installation) as well as Automatic startup.
Reboot the computer.
 
Processes that are being killed using TaskManager will not fire any event in
the application and therefore cannot be cancelled, since they are simply
abruptly terminated.

I believe the Closing event fires - one of the CloseReason values is
TaskManagerClosing, so you have an opprortunity to clean up - the close is
not really abrupt. But Cancel=True does not work. This aspect of windows
and .net is poorly documented imo.
 
AMercer said:
I believe the Closing event fires - one of the CloseReason values is
TaskManagerClosing, so you have an opprortunity to clean up - the close is
not really abrupt. But Cancel=True does not work. This aspect of windows
and .net is poorly documented imo.

Well, yes and no. If you end the application using the application tab in
TaskManager, you will indeed get the Closing event and you can prevent the
application from closing. The CloseReason will be TaskManagerClosing. If
you instead end the process using the process tab you will not get any
notification since the process is abruptly killed.
 
Please Guys it is realy urgent
Even if it hides the process from the Task Manager Process's List
 
Hi,

To sum up. The only way you can prevent a user from terminating the process
is by ensuring the user runs with limited privileges. If the user runs as
administrator he will be able to terminate the application one way or the
other.

There is a trick that may work, or at least make it harder to shut down the
program. Launch two programs and have one program start the other. Have the
programs continously polling each other to immediately restart a program that
was shut down.
 
Back
Top