tags:

views:

87

answers:

3

Hi,

how can I catch windows taskkill command in order to prevent it?

+1  A: 

I'm pretty sure it is not possible, otherwise a single application could stop windows from ever shutting down. Even when the process is hung, killing it in task manager eventually works. If it was possible, malicous software, etc would probably have a hey-day using it - not only could they take control of various parts of your PC, they'd make sure you could never get it back again.

Paul Hadfield
+7  A: 

You cannot prevent your process being killed. The only way to keep a program alive is to have a second Watchdog application that is constantly pooling that process to ensure it's running.

So, you have two Applications; AppA (Main) and AppB (Watchdog).

AppA checks if AppB is running. If not, AppA starts AppB.

AppB checks if AppA is running. If not, AppB starts AppA.

But this is usually a design for a malicious process, so I hope you're not doing anything untoward.

You can see the following events in the message queue when End process is clicked:

WM_CLOSE // UI app

CTRL_CLOSE_EVENT // Console app

But if your application does not close in a timely manner, then the kill command will be sent, which cannot be captured.

GenericTypeTea
A: 

Is it possible for you to run your program on/under the administrator account? Perhaps it would be to highly privileged to be killed by an ordinary user?

Marcus Johansson