You cannot prevent your process. The only way to keep the program in life is to have a second Watchdog application that constantly integrates this process to ensure its operation.
So, you have two Applications; AppA (Main) and AppB (Watchdog).
AppA checks to see if AppB is AppB . If not, AppA launches AppB .
AppB checks if AppA is AppA . If not, AppB launches AppA .
But this is usually a design for a malicious process, so I hope you are not doing anything unpleasant.
In the message queue, you can see the following events when you click End Process :
WM_CLOSE // UI Application
CTRL_CLOSE_EVENT // Console Application
But if your application does not close in a timely manner, then the kill command will be sent, which is impossible to capture.
source share