Search code examples
c#eventsprocessconsoleipc

Capture .Net Console Kill or Terminate


So I have a hidden console application called Hidden.exe running. Another application Call Killer.exe will find the process Hidden.exe or its PID, and Kills the process.

How do i programmatically capture a kill command or a terminate from Task Manager? A user can browse through the process list and 'End Task' on Hidden.exe and I want to be able to capture this event and do some cleanup before it exits.

How can i do this? I have searched around, and explored alternatives from
.NET console application exit event
Send WM_CLOSE message to a process with no window
Can I send a ctrl-C (SIGINT) to an application on Windows?
etc....

But they all dont work or only work in some cases, my case is for a hidden console application and needs to somehow capture a Kill on it. None of the above solution seem to have a 'correct' solution.


Solution

  • There is no such answer. A kill will always work and will fire no event. This is due to security concern to prevent virus and/or malware code.

    I've since found another way.