Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / Delphi - preventing user to exit application (not hax, it's for my job)

Author
Message
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 13th Sep 2006 15:36
Hello,
i got a task to try and prevent the user from exiting an application.

the application is a web browser where you can only navigate on one website. it is to be used in the library where people can search for books when they don't know where to look.

i have tried this:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=false;
end;

that prevent the user from closing the application.

next i want to disable the use of [winkey]+M and simply [winkey].
i tried:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=VK_LWIN) or (Key=VK_RWIN) then Key:=0;
end;

that didn't quite work..

so i would need help with
* how to prevent the maximize and minimize to a smaller window function (i can hide the buttons, but i can still double click the border)
* how to disable the use of the WinKey and any combinations used with WinKey
* how to prevent the user from opening CTRL-ALT-DEL.

i think that i could do this through windows, under user policy because the computer will be logged in with a special user, but i don't know how to do that either i also looked under mmc.exe but i couldn't find anything.

so any help would be appreaciated.

hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Sep 2006 21:43
For disabling closing the application, simply put this code in the onClose event:

That will disable closing it with alt + f4 also. You'll have to use the task manager to kill it. Be warned, this can seriously mess up the Delphi debugger, though. If you need to close your application while debugging, use ctrl + f2 while in Delphi.

As for disabling minimizing, etc. I'm sure you can do it, but I don't exactly remember right off. You might have to capture a WinAPI message for that. I just don't have time to look into it in detail.

Disabling ctrl+alt+delete is probably something that you'll have to take care of with the security policies on XP.

Good performance is better than a good excuse.
CodeSurge -- DBP Editor for serious programmers.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Sep 2006 00:41
Quote: "how to prevent the maximize and minimize to a smaller window function"


The best you can probably do is to automatically maximise your application window when a window-resize event comes along. You probably have to override the forms FormResize event handler to do this.

Quote: "how to disable the use of the WinKey and any combinations used with WinKey"


Write a system-wide low-level keyboard hook. Of course, that will trip up most virus checkers and spyware detectors that will give the option to stop it dead at startup.

If you still want to do this, then google it - I've done it in C++, but wouldn't have a clue for Delphi.

Quote: "how to prevent the user from opening CTRL-ALT-DEL"


Bad. Really bad. Really really bad. It's the one way that you have to sure that your windows login isn't a dummy. If you really need to do it for some reason, then the keyboard hook is probably the easiest way to go about it.

Now I've steered you a little, can you tell me exactly how you plan on shutting your application down cleanly if you need to with all of the above in place, and how you plan to test it wothout locking up your development machine when you make a mistake in the code?

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 14th Sep 2006 19:30
Nah, the task manager problem is actually quite easy:

Simply get a copy of resource hacker (google it), make a copy of tskmgr.exe in the system32, back up the original.

Open up tskmgr in res hacker, and open up the main dialog. I believe there is an option to see the context menu for processes. Simply erase the 'End process' context option, and delete end process button from the form.

As long as you keep the backup intact, you can still 'new up' explorer if something like login fails etc.

Quote: "Why would anyone spend that kind of money on rubber jewellery? - Phaelax"
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 15th Sep 2006 06:06 Edited at: 15th Sep 2006 06:08
IanM - to add:
1. If you can set the properties of your main window when it is created, you can strip the min/max buttons, or disable them. You will have to catch events for most of the rest that you cannot get at in Delphi otherwise.

2. Once you need more than Delphi (Or VB, for that matter) can provide, you should go immediately and completely to where your window is created, and make your solution there. It does not pay to fight Windows in any language. I have learned to find out how they do it, and where they do it...and lift that. WNDCLASS and CREATSTRUCT are your friends because Windows will happily provide you what you want, as long as you know where and how to ask.

CTL_ALT_DEL is BADDD! Shame on you! (You could hook the INT VECTOR!!!!!) I know that would wake up your virus checker, for sure.
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 15th Sep 2006 10:24
thanks alot for the tips, i got the close to be disabled (thanks to hyricher) and the minimize/maximize to be disabled (thanks to IanM).

i will leave the rest to my boss for now, so i don't do anything stupid

the reason why i got this task was because he wasn't going to be here yesterday so i had the 13th and 14th to develop this, so he wouldn't have to. i thought it was a fun task, and i got a reason to open delphi again and refresh my skillz! (allthough i don't know much :/ ).

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Sep 2006 15:43
@jinzai, "you can strip the min/max buttons, or disable them"

Yes, but you can't stop people minimising the window using Win-M, or selecting the Show Desktop button if it's available, or left-clicking on the top-left button on the menu - that's why you need to automatically maximise on a resize ... and probably force the window to the front too.

@Lukas,

As you can see from what I've just said, then you still need to override the FormResize event.

Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 15th Sep 2006 17:14 Edited at: 15th Sep 2006 17:20
Quote: "and probably force the window to the front too"

would that not bring it on top of the start menu? and the task manager aswell? i have seen games that do this. (mostly when the game freeze and i want to close it, the only solution i have found to this is to reboot).

edit,
do you think another solution would be to create an account with super restricted rights?
like in the start menu the only thing s/he'll find is the name of the application (or something similar).

so if user press ctrAltDel and close the application, the only thing s/he can do next is to open it up again.

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th Sep 2006 13:28 Edited at: 16th Sep 2006 13:30
IanM, sorry...I should have made it clear that that is what I meant later in that item when I spoke about catching events....which was what you said at the outset WRT to Resize. My bad.
Yes, I remember the whole z-order thing, too...what a mess

Login to post a reply

Server time is: 2025-06-06 09:52:23
Your offset time is: 2025-06-06 09:52:23