Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ctrl-Alt-Delete 1

Status
Not open for further replies.

gpalmer711

IS-IT--Management
May 11, 2001
2,445
0
0
GB
Does anyone know how to intercept Ctrl-Alt-Delete and Alt-Tab Keyboard commands before windows processes them. I am writing a piece of software for children and need to make sure they can not exit the program. I know that it is possible because password protected screen savers will display the password box when you ctrl-alt-del instead of displaying the taskmanager.
Thanks
 
Also any ideas on intercepting the Windows Key?
 
This snippet from MSDN may be of interest to you:

========================================================
Open a new project and add the variable ShiftKey to the Declarations section of the form:

Dim ShiftKey as Integer

Add a Textbox control to the form and this procedure in the KeyDown event:

Private Sub Text1_KeyDown(KeyCode As Integer, _
Shift As Integer)
ShiftKey = Shift And 7
Select Case ShiftKey
Case 1 ' or vbShiftMask
Print "You pressed the SHIFT key."
Case 2 ' or vbCtrlMask
Print "You pressed the CTRL key."
Case 4 ' or vbAltMask
Print "You pressed the ALT key."
Case 3
Print "You pressed both SHIFT and CTRL."
Case 5
Print "You pressed both SHIFT and ALT."
Case 6
Print "You pressed both CTRL and ALT."
Case 7
Print "You pressed SHIFT, CTRL, and ALT."
End Select
End Sub

==================================
The whole article can be found under "The KeyDown and KeyUp Events"

Good luck.


Min
 
Thankyou very much for your help but I have already tried this. Unfortunatly It will not intercept Ctrl-Alt-Del.
 
Check out this article at one of the best site for API:

And they have one article has the code to disable those key you want. It says that the code works in Win95, but I think a similar article in MSDN also mentions that the code works in Win95 & Win98.

Good luck.

===================================================
How can I disable CTRL-ALT-DEL and ALT-TAB and CTRL-ESC ?
Sometimes it is necessary for a program to prevent the use of the
CTRL+ALT+DEL key combination to bring up the Close Program task list to end
a task or shut down Windows 95 and to prevent the use of the ALT+TAB key
combination to switch tasks. The following technique uses the
SystemParametersInfo API to trick Windows 95 into thinking that a screen
saver is running. As a side effect, CTRL+ALT+DEL and ALT+TAB are disabled.

The Win32 SDK states:
"SPI_SCREENSAVERRUNNING Windows 95: Used internally; applications should
not use this flag. Windows NT: Not supported."

Note that disabling CTRL+ALT+DEL is not recommended because the Close
Program dialog box was created to enable users to terminate misbehaving
applications. If a program "hangs" while CTRL+ALT+DEL is disabled, it may
not be possible to terminate it by any method other than rebooting the
machine, which could result in the loss of data.

You will need two command buttons for this program.

Private Const SPI_SCREENSAVERRUNNING = 97&
Private Declare Function SystemParametersInfo Lib "User32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long

Private Sub Form_Load()
Command1.Caption = "Disabled"
Command2.Caption = "Enabled"
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Re-enable CTRL+ALT+DEL and ALT+TAB before the program terminates.
Command2_Click
End Sub

Private Sub Command1_Click()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, _
blnOld, 0&)
End Sub

Private Sub Command2_Click()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
blnOld, 0&)
End Sub

Press the F5 key to run the program, and click the "Disabled"CommandButton. CTRL+ALT+DEL and ALT+TAB and CTRL-ESC are disabled. Click the "Enabled" CommandButton to enable CTRL+ALT+DEL and ALT+TAB and CTRL-ESC again.

==========================================
 
Oh, in the same site I mentioned, there's another article that goes....

============================

Hiding Your Program in the Ctrl-Alt-Del list
The easiest method is probably by using the TaskVisible property of the App-object. If you set it to False, the task will be hiden from the CTRL-ALT-DEL-list. If you set it to True, your task will reappear again.
'Hide from list
App.TaskVisible = False
'Show on list
App.TaskVisible = True

Thanks to Fernando Robles for this tip.

There is another, more complicated way to accomplish the same effect.
You can register your program as a service. This is done by passing the process ID of your application to the RegisterService API.

Declarations

Copy the following code into the declarations section of a module:

Public Declare Function GetCurrentProcessId _
Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess _
Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess _
Lib "kernel32" (ByVal dwProcessID As Long, _
ByVal dwType As Long) As Long

Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0

Procedures

To remove your program from the Ctrl+Alt+Delete list, call the MakeMeService procedure:

Public Sub MakeMeService()
Dim pid As Long
Dim reserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub

To restore your application to the Ctrl+Alt+Delete list, call the UnMakeMeService procedure:

Public UnMakeMeService()
Dim pid As Long
Dim reserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, _
RSP_UNREGISTER_SERVICE)
'End Code

Don't forget to unregister your application as a service before it closes to free up system resources by calling UnMakeMeService.


==========================================

I'm going to try it out in Win2K to see if it works.

Good luck to u.


Min.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top