We help IT Professionals succeed at work.

prevent application getting terminated in task manager

jimsweb
jimsweb asked
on
I am creating a company wide policy update program. But users are closing it using the task manager. Just wanted to know how can I prevent my application  getting terminated via task manager.

so far, I have managed to restart if it gets closed in task manager's application tab. But it can be killed in processes tab. Can somebody help me to make it restart if it gets closed in taskmanager's processes tab..?

procedure TForm1.Button1Click(Sender: TObject);
begin
  closeit := true;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if closeit = true then
  begin
    ;
  end
  else
  begin
    Application.Terminate;
    Shellexecute(0, '', PCHar(paramstr(0)), '', '', sw_ShowNormal);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.Terminate;
  Shellexecute(0, '', PCHar(paramstr(0)), '', '', sw_ShowNormal);
end;

Open in new window

Comment
Watch Question

Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
I don't think you can control the close from Task Manager in the application itself.  I believe you will have to set it to be a system run program.

Have you checked if it is possible to keep users out of Task Manager?

mlmcc
Ephraim WangoyaSoftware Engineer

Commented:

You could create a service instead of a normal application.

Author

Commented:
thanks fro your comments.
As you can see, i have managed to restart whenever the user closes my application from task manager's application tab. in the same way, is there any technique to restart my application from task manger's processes tab..?

Author

Commented:
@ mlmcc
It is not possible to disable taskmanager from users machines.

Is it possible for me to start a delphi application as started by system..? so that it cannot be terminated by user.
developmentguruPresident

Commented:
If you redid it as a service (and it sounds like this would be perfect as a service) then it would be run "as started by the system".  A service gets a request to close message sent to it.  

this link shows some of the SC (Service Control) command line options that can be sent.  I include this just to show the request types.
http://www.liberidu.com/blog/?p=304

I would look into making your response to a close request check if the OS is in shutdown mode and fail otherwise.  This would be an experiment on my part... I have run into services that fail to stop when requested in the past but you would need to carefully look for unintended effects.
Top Expert 2014

Commented:
I would address this through policies.  Assuming that this program is running under admin authority (or has been recommended as a service), your end users should not be able to affect such processes.

Your users should not be admins.
Commented:
i solved it using two exes'.

Author

Commented:
i solved it myself
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
How does that solve it?
If you simply added a second task to watch for the closing of the first and then restart it, what prevents a user from terminating the watcher first then the one you want running?

mlmcc

Author

Commented:
the main exe watches the watcher exe and vice versa.