Solved

Prevent shutdown of program

Posted on 1998-05-25
9
225 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:carceri
9 Comments
 

Expert Comment

by:gnom
ID: 1347652
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.... ?

dejan
0
 
LVL 4

Expert Comment

by:d003303
ID: 1347653
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.

Slash/d003303
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347654
carceri

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

Later
BoRiS
0
 
LVL 2

Expert Comment

by:rene100
ID: 1347655
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)

regards
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1347656
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);
begin
  case Message.Msg of
    WM_DESTROY:
      if (not IsClosing) then
        WinExec(PChar(ParamStr(0)), SW_SHOWNORMAL);
    WM_CLOSE:
      IsClosing := True;
    WM_QUERYENDSESSION:
      begin
        IsClosing := True;
        Close;
      end;
  end;
  inherited WndProc(Message);
end;

Cheers,
JB
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1347657
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)
0
 

Author Comment

by:carceri
ID: 1347658
Yes, please !
0
 
LVL 7

Accepted Solution

by:
ahalya earned 50 total points
ID: 1347659
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.
e.g:-

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").
0
 

Author Comment

by:carceri
ID: 1347660
Thanks, that's just what I need !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 211
Delphi component that can load a DLL in design time? 8 53
HTML text in the body of an email (delphi code) 12 96
Working with hours 3 46
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now