-
Ctrl+Alt+Del Trap
Hi all,
How can I trap Ctrl+Alt+Del Keys and Alt + Tab keys so that once the vb application is running
no user is able to go to any other application or
end task the application only by the option in the
applicaiton it should be allowed.
Thanks in advance for the help.
Deepak Adlakha.
-
Re: Ctrl+Alt+Del Trap
To prevent the user switching off your application:
1) Download the EventVb.OCX from http://www.merrioncomputing.com/Download/index.htm
2) Add it to your application and put an EventWindow control onto your application's main form.
3) In the form load, connect the eventVB EventWindow control thus:
private Sub Form_Load()
VBEventWindow1.ParentWnd = me.hWnd
End Sub
4) Put code in the ActiveApplicationChanged event thus:
private Sub VBEventWindow1_ActiveApplicationChanged(byval ActivatingThisApp as Boolean, byval hThread as Long, Cancel as Boolean)
If Not ActivatingThisApp then
'\\ Prevent application switch
Cancel = true
End If
End Sub
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
Re: Ctrl+Alt+Del Trap
Was unable to get VBEventWindow1.parentwnd property.
made the changes in the code of eventvb.ocx and
activated the Parentwnd property.
The error was removed at the load of the form now.
but Alt+Tab and Ctrl+Alt+Del is behaving as it
behaves in windows.
and my form is losing its focus.
kindly guide for the same.
thanks
deepak adlakha.
-
Re: Ctrl+Alt+Del Trap
Note that EventVB.OCX does not trap CTRL+ALT+DEL as this not sent as a windows message. There is a workaround I have seen whereby you convince windows that a screen saver is running but I have never tried it myself.
To prevent your application losing focus you need to intercept the WM_ACTIVATEAPP message and where it is issued to tell you that another application has got the focus you need to prevent the message being processed and set the focus back to your application.
What you need to do is check that any messages at all are being sent to your application by putting the following in your code:
private Sub VBEventWindow1_WindowMessageFired(byval msg as WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)
Debug.print msg
End Sub
If this does not print anything when your application is running then you have not set the ParentWnd member correctly or an error has occured.
The VBEventWindow control has an error message that you should put code in to check if an API error is causing you any problem:
private Sub VBEventWindow1_ApiError(byval Number as Long, byval Source as string, byval Description as string)
MsgBox Description, vbCritical, "error in " & Source
End Sub
If the window is recieving messages then you need to check whether the WM_ACTIVATEAPP message is being recieved. This message is ONLY sent to top level application windows.
Try:
private Sub VBEventWindow1_ActiveApplicationChanged(byval ActivatingThisApp as Boolean, byval hThread as Long, Cancel as Boolean)
Debug.print "WM_ACTIVATEAPP called"
End Sub
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
Re: Ctrl+Alt+Del Trap
Please note, the property has been changed to ParentForm
i.e.
private Sub Form_Load()
VbEventWindow1.ParentForm = me.hWnd
End Sub
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
Re: Ctrl+Alt+Del Trap
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (byval _
uAction as Long, byval uParam as Long, byref lpvParam as Any, byval fuWinIni as Long) as Long
private Const SPI_SCREENSAVERRUNNING = 97
private Sub Form_Load()
'Disable HotKeys, including. CTRL+ALT+DEL and ALT+TAB
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, byval 0&, 0&)
End Sub
'ReEnable HotKeys
private Sub Form_Unload(Cancel as Integer)
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, byval 0&, 0&)
End Sub
Iouri Boutchkine
iouri@hotsheet.com
-
Re: Ctrl+Alt+Del Trap
There are some sample programs on Http://www.Planet-Source-Code.com/vb for disabling the Ctrl-Alt-Del key sequence. GO there and search on "Ctrl alt del" (without the quotes of course).
John G
-
Re: Great
This is great, Iouri. Just a pity it works on win 95/98/Me only and that I am already out of votes...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
-
Re: Ctrl+Alt+Del Trap
I'm nearly sure its a bad idea to prevent the user from pressing CTRL+ALT+DEL - what if you do so and then the app hangs? The user would have to switch off the machine while it was running....not something I'd like on my conscience.
You can (in NT /2000) get a message when the system is being suspended/hibernated/shut down and return a value to say that you don't want the system to close down...is that what you wish to do?
There are also code hacks on PlanetSourceCode to hide your app from the TaskList (but again - is that a good idea?).
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
Re: a good idea...
I agree that in most common situations it would be a bad idea, but some specific circumstances may require this kind of knowledge. So, let's share!
:-)
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
-
Re: Ctrl+Alt+Del Trap
You cannot block alt+ctrl+delete on Windows NT. Even using a low-level keyboard hook doesn't work.
NT traps this key combination before the event handler gets it and automatically handles it. The only way
that you could do anything about it would be to write your own GINA dll which receives this event from the
O/S however this is an extremely complex task as the GINA controls a hell of a lot of stuff as well as
handling Ctrl+Alt+delete.
Iouri Boutchkine
iouri@hotsheet.com
-
Re: Ctrl+Alt+Del Trap
Thanks buddy
this site has helped me to find out the solution.
Following is the code which I have embedded in my
program for the desired output.
/vbcode
'Declare the following two lines in a Module.
Public Declare Function SystemParametersInfo2 Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97
' Create these two methods
Public Sub CtrlAltDel_Disable()
Dim syssend As Long
syssend& = SystemParametersInfo2(SPI_SCREENSAVERRUNNING, True, False, 0)
End Sub
Public Sub CtrlAltDel_Enable()
Dim syssend As Long
syssend& = SystemParametersInfo2(SPI_SCREENSAVERRUNNING, False, True, 0)
End Sub
'on the form load or any button invoke the desired method.
Private Sub Form_Load()
CtrlAltDel_Disable
End Sub
/vbcode