Prevent shutdown of program

How can I prevent people from shutting down one of my programs. The program must run in the background, I can set the CanClose to false, but when you press Ctrl-Alt-Delete and choose end task, the program comes with the not responding message after a while, and then you can choose to shut it down
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hi carceri

why do you need that ?

in WindowsNT there is no way to prevent people from shutting down any process.
and i think this is very good because if a process hangs you can shut it down, no matter what kind of process.

maybe it's enough do hide your program from the taskbar so the average user does not know how to shut down your program.... ?

On NT you could run your app as a service. The service process cannot be killed in task manager, only on the command line with kill (included in the NT ResKit) or in the service control manager. For both of that, you need administrative privilegues.


the other option is to disable ctrl + alt + del and ctrl + tab totally while you app is running, that way until you kill your app no one can get to the end task etc.(unless they run taskman from start/run)

If you want the code let me know

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

if the program runs everytimes in the background, you could start
to instances of it, and every instance checks if the other is still running and restart it when needed.
(very strange, i know)

Hi all

rene100's solution is a reasonable solution under Win 95.  Another method (which I have used) needs only one instance of the exe, instead of rene100's 2 instanced which check each other.

(gnom: if you hide your app from the taskbar, it still shows up in the Task Manager.)

I have noticed that when you Ctrl-Alt-Del & End Task, the tasks main window gets a WM_DESTROY, but NOT a WM_CLOSE.  (Normally the app gets a WM_CLOSE and then a WM_DESTROY.  But when you select End Task the WM_CLOSE doesn't arive.)

Thus, you can check in the WM_DESTROY if a WM_CLOSE has been called.  If not, then re-run the app.  (It's also not elegant, because the app has to be restarted...)

E.g.  Declare a form variable called IsClosing, and check this variable in WM_DESTROY.  (You also need to override the WndProc for the form.)

procedure TMyForm.WndProc(var Message: TMessage);
  case Message.Msg of
      if (not IsClosing) then
        WinExec(PChar(ParamStr(0)), SW_SHOWNORMAL);
      IsClosing := True;
        IsClosing := True;
  inherited WndProc(Message);

The best way to do this would be to hide the program from the task list. (so that the user cannot "End Task" from the task list.)

This can be done for Win95, by making your program a "simple service". i can let you know the details if you like. (This DOESN'T work on NT though)
carceriAuthor Commented:
Yes, please !
Declare this external function just above your implementation section:

function RegisterServiceProcess (ThreadID : THandle; Flags : Integer):
Integer; stdcall; external kernel32 name 'RegisterServiceProcess';

and in your FormCreate  call the function.

const      r = 1;
                 u = 0;

if RegisterServiceProcess (0, r) = 0
   then  ShowMessage ('Error Hiding Application')
   else  ShowMessage ('Application is now hidden from the task list !')

This hides your program from the win95 tasklist and you can now have a program that's always alive !

(if you want to show it back in the tasklist then call it with the argument of 0 -my const "u").

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carceriAuthor Commented:
Thanks, that's just what I need !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.