Hi!

Does anybody knows a good method to prevent the user from closing my program or switching to another by using the most common methods like Alt+Tab or Ctrl+Alt+Del or so ...
this should work on all win platforms if possible

thx for any idea
Posted on 2003-09-14 05:40:33 by ChigpA
I guess a low level keyboard hook would work in XP/2000...don't know how to do it in win9X
Posted on 2003-09-14 06:08:21 by Delight
ChigpA,

The Ctrl+Alt+Del key combination can be disabled by using the RegisterServiceProcess API
function available in Win 9x
Posted on 2003-09-14 07:25:03 by Vortex
can you tell me more about the (low level) keyboard hook. I read something about the SetWindowsHookEx function or something like that.
But the best would be a real example to solve this ...

thx
Posted on 2003-09-14 09:44:29 by ChigpA
I don't think you can in NT, even with hooks.... luckily. I would never use a program that disables these keys. What do you need it for?

Thomas
Posted on 2003-09-14 10:07:26 by Thomas
I need it for a kind of password dialog and if the user does not know the password he should not be able to switch to another program (brute force or so) or close the dialog
Maybe I do it like: the user has 3 tries and if he does not get it the computer shuts down, so that he gets rid of trying this and if he could use Alt+Tab or so, than he can abort after the second try and execute the dialog again without having this Reboot everytime

hope you got my idea

thx
Posted on 2003-09-14 10:28:32 by ChigpA
Hmm, but alt+tab, ctrl+alt+del etc. are not the only ways to get out of a program, what about hotkeys registered by other programs, autorun CDs, running programs remotely using a network, etc? It's pretty hard to make such a thing fool proof as a user mode application...

Thomas
Posted on 2003-09-14 14:07:20 by Thomas
when i was looking into making my own desktop... i found out that Screen Savers are also desktops... anyway when i did end up creating somewhat of a desktop when i did alt+ctrl+del it would load the program but could not be seen.. since it was not created on my desktop.. the only way i could get back to the other desktop is have my program do it...

it may have also been possible for me to kill the other process by accidentally killing it in the invisible process manager but a easy way to make the impossible is to set that window in active or if possible since a desktop is still sort of a window set it back to the process in use... like ever couple seconds..

these are just ideas..
Posted on 2003-09-14 14:13:58 by devilsclaw
Here is were i left off... this will run the progman program and will close its self after either 30 or 60 seconds cant remember..



; #########################################################################

.386
.model flat, stdcall
option casemap :none ; case sensitive

; #########################################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib
; #########################################################################

;=============
; Local macros
;=============

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

m2m MACRO M1, M2
push M2
pop M1
ENDM

return MACRO arg
mov eax, arg
ret
ENDM

;=================
; Local prototypes
;=================
EnumWindowsProc proto :DWORD,:DWORD
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD
ListBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
EditBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ButtonBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ListBoxProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
ReadPffFileInside PROTO :DWORD
Extract PROTO :DWORD
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.const

.data
DesktopName db "Desktop2",0
DesktopName1 db "Desktop1",0
szND1TXT db "Input Desktop Not Found",0
szND1CAP db "Error 1",0
szND2TXT db "Error Creating New WorkStation",0
szND2CAP db "Error 2",0
szND3TXT db "Error Setting Access To New WorkStation",0
szND3CAP db "Error 3",0
szND4TXT db "Error Creating New Desktop",0
szND4CAP db "Error 4",0
szND5TXT db "Error Switching To New Desktop",0
szND5CAP db "Error 5",0
szND6TXT db "Error SetThreadDesktop",0
szND6CAP db "Error 6",0
Run_Buffer db "progman.exe",0

.data?
Blank dd ?
Blank1 dd ?
Blank2 dd ?
Sec SECURITY_ATTRIBUTES <>
Sec2 SECURITY_ATTRIBUTES <>
hDesktop dd ?
hNDeskTop dd ?
OldDesk dd ?
pvInfo USEROBJECTFLAGS <>
pvSize dd ?
ProcessInfo PROCESS_INFORMATION <>
StartupInfo STARTUPINFO <>
lParam2 dd ?
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

start:
invoke OpenInputDesktop,DF_ALLOWOTHERACCOUNTHOOK,TRUE,DESKTOP_CREATEMENU or DESKTOP_CREATEWINDOW\
or DESKTOP_ENUMERATE or DESKTOP_HOOKCONTROL or DESKTOP_JOURNALPLAYBACK\
or DESKTOP_JOURNALRECORD or DESKTOP_READOBJECTS or DESKTOP_SWITCHDESKTOP\
or DESKTOP_WRITEOBJECTS
mov OldDesk,eax
cmp eax,NULL
je NoDesk1

mov Sec.nLength,0Ch
mov Sec.lpSecurityDescriptor,NULL
mov Sec.bInheritHandle,TRUE
invoke CreateWindowStation,offset DesktopName,Blank,WINSTA_ACCESSCLIPBOARD or WINSTA_ACCESSGLOBALATOMS\
or WINSTA_CREATEDESKTOP or WINSTA_ENUMDESKTOPS or WINSTA_ENUMERATE\
or WINSTA_EXITWINDOWS or WINSTA_READATTRIBUTES or WINSTA_READSCREEN\
or WINSTA_WRITEATTRIBUTES,offset Sec
mov hDesktop,eax
cmp eax,NULL
je NoDesk2

mov Sec2.nLength,0Ch
mov Sec2.lpSecurityDescriptor,NULL
mov Sec2.bInheritHandle,TRUE
invoke CreateDesktop,offset DesktopName1,Blank1,Blank2,DF_ALLOWOTHERACCOUNTHOOK,DESKTOP_CREATEMENU\
or DESKTOP_CREATEWINDOW or DESKTOP_ENUMERATE or DESKTOP_HOOKCONTROL\
or DESKTOP_JOURNALPLAYBACK or DESKTOP_JOURNALRECORD or DESKTOP_READOBJECTS\
or DESKTOP_SWITCHDESKTOP or DESKTOP_WRITEOBJECTS,offset Sec2
mov hNDeskTop,eax
cmp eax,NULL
je NoDesk4


invoke SetProcessWindowStation,hDesktop
cmp eax,NULL
je NoDesk3

invoke SetThreadDesktop,hNDeskTop
cmp eax,NULL
je NoDesk6

invoke SwitchDesktop,hNDeskTop
cmp eax,NULL
je NoDesk5



;mov pvInfo.fInherit,TRUE
;mov pvInfo.fReserved,FALSE
;mov pvInfo.dwFlags,WSF_VISIBLE or DF_ALLOWOTHERACCOUNTHOOK
;invoke SetUserObjectInformation,hNDeskTop,UOI_FLAGS,offset pvInfo,14h
;cmp eax,NULL
;je NoDesk6

invoke CreateProcessA,0,offset Run_Buffer,0,0,0,0,0,0,offset StartupInfo,offset ProcessInfo
invoke Sleep,20000
invoke CloseDesktop,hNDeskTop
invoke ExitProcess,NULL

jmp Exit

NoDesk1:
invoke MessageBoxA,NULL,offset szND1TXT,offset szND1CAP,MB_OK
jmp Exit

NoDesk2:
invoke MessageBoxA,NULL,offset szND2TXT,offset szND2CAP,MB_OK
jmp Exit

NoDesk3:
;int 3
invoke MessageBoxA,NULL,offset szND3TXT,offset szND3CAP,MB_OK
jmp Exit

NoDesk4:
invoke MessageBoxA,NULL,offset szND4TXT,offset szND4CAP,MB_OK
jmp Exit

NoDesk5:
invoke MessageBoxA,NULL,offset szND5TXT,offset szND5CAP,MB_OK
jmp Exit

NoDesk6:
invoke MessageBoxA,NULL,offset szND6TXT,offset szND6CAP,MB_OK

Exit:
invoke CloseDesktop,hNDeskTop
invoke ExitProcess,NULL

end start
Posted on 2003-09-14 14:34:47 by devilsclaw
i tested the alt+ctrl+del and tryed to kill the process and i cant.. so this might be what you looking for if you can figure out how to make a dialog show up....
Posted on 2003-09-14 14:59:06 by devilsclaw
You need to write keyboard driver in Windows NT/2000/XP, then you can filter keystrokes before NT even sees them. Check Ctrl2Cap utility on sysinternals.
Posted on 2003-09-14 15:54:24 by comrade
Hi, ChigpA
If you are using password dialog, you also might try DirectInput metods to get user input from keyboard.
This also allows you to set proper cooperative level and acquire the keyboard, so it will not (easily) work in other apps. This isn't so easy but additionally you can add some tricks to your keyboard scanner, since you're interesting in protection.
Posted on 2003-09-14 20:34:10 by S.T.A.S.
Now I know setting low level keyboard hooks don't work in 2000 to stop people from doing CTRL-ALT-DEL (although it will let you see it -- it won't let you respond to it) -- However, you can disable every other key combination that way (ALT-TAB, ALTF4, etc).

There are multiple ways to disable keys on the 2000 station (in the registry Coolswitch = 0 -- disables alt -tab (doesn't work for all service packs ) or modify the gina32.dll (I think this is the right dll -- been a while) and edit the resource to prevent locking the work station...

98 is easy to lock down and there are sources on iczelions web site that explain how to do it...

The driver is prob. your best bet...

Sliver

----
EDIT: spelling :) at least a glaring one...
Posted on 2003-09-15 06:07:23 by Sliver

I would never use a program that disables these keys.



Ditto. You will generally find that users will not appreciate a program that takes system control away from them. This kind of thing is among the cardinal sins of UI design.
Posted on 2003-09-15 07:41:06 by iblis
No, no no.

I've seen plain api examples of this in some Direct3D code online, but can I find anything when I look for it?

Disabling the Windows key and control alt delete and alt tab can be done under NT/XP without resorting to obscure api.

If and when I find it again I'll be sure to post it.

(Yeah thanks, Homer - that was as useful as tits on a bull !!)
Posted on 2003-09-15 10:46:32 by Homer
Please tell me if this one still works :
.data
MyW WORD NULL
.code
invoke SystemParametersInfo, SPI_SCREENSAVERRUNNING,1,addr MyW,NULL



should disable all those nasty key combinations - you are basically telling the OS that your application is in fact a screensaver (LOL)

To re-enable the keys, change the 1 to a 0.

FYI the CoolSwitch registry hack won't work on any NT with service patches.
Posted on 2003-09-15 10:57:32 by Homer
In Iczelion's tutorials this is also mentioned (SystemParametersInfo), but he said it'll work on Win 98 only and this is not what i want
Posted on 2003-09-15 12:51:55 by ChigpA
Hi, everyone.

Do you really want to disable this hotkeys? Maybe it would be easier to process other messages, for example when the focus is drawn to a window that doesn't belong to your app, set the focus back again to yours. Same thing when activating windows or bringing them to foreground.

Also, setting the taskbar as your window's parent seems to cause the Ctrl-Alt-Del dialog to try to shut down Explorer instead of your app (at least on Win98, I didn't try NT systems but it should be different). That brings the Windows shutdown dialog when the user tries to close your app... :grin:
Posted on 2003-09-15 17:24:52 by QvasiModo


FYI the CoolSwitch registry hack won't work on any NT with service patches.


I think I mentioned that it doesn't work on all service packs :) However, I didn't know it didn't work on all service packs though... Which is odd because it worked for a time on my 2000 box at one point...

Maybe it was just me :grin:

Sliver
Posted on 2003-09-16 03:47:05 by Sliver