The people from Microsoft decided that the user has to be in full control over the computer. So there is no assured way to make a program user resistant. She can always use TerminateProcess to forcibly kill the process.

uses JwaWindows;

function KillProcess(const ProcessID : DWord): Boolean;
var
  hProcess: HANDLE;
begin
  hProcess := OpenProcess(PROCESS_TERMINATE,  False, ProcessID);
  Result := TerminateProcess(hProcess, 0);
end;

Because nobody reads the remarks section of TerminateProcess, I cite it here.

The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.

TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.

And remind this little sentence.

A process cannot prevent itself from being terminated.

However there are some reasons not to make your application undestroyable.

  1. The users don’t want it.
  2. The work does not pay off. The user is going to close the app anyway.
  3. Some people complain about apps that do not close when Windows is shutting down.
  4. It’s also said that there were laptops which didn’t shutdown. The users put them into their bags and didn’t realize that the machine overheated eventually.
  5. Vista closes your application in the end you have no veto.

Tell me how you liked this blog entry by adding a comment.