strickdd
asked on
Prevent Certain Key Combinations
I am trying to prevent certain keyboard shortcut combination keys from being pressed. Mostly I want to stop people from pulling up the task manager by CTRL + ALT + DEL. Here is what I have tried so far:
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles MyBase.KeyDown
If (e.Control) Then
KeysPressed += "True"
ElseIf (e.Alt) Then
KeysPressed += "True"
ElseIf (e.KeyCode = Keys.Delete) Then
KeysPressed += "True"
End If
If (KeysPressed.IndexOf("True TrueTrue") ) Then
e.Handled = True
End If
End Sub
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles MyBase.KeyDown
If (e.Control And e.Alt And e.KeyCode = Keys.Delete) Then
e.Handled = True
MessageBox.Show("Handled")
End If
End Sub
Neither of these will handle multiple keys pressed at once. They both handle them in the order they occur. Any help would be great! Thanks!
Strickdd
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv
If (e.Control) Then
KeysPressed += "True"
ElseIf (e.Alt) Then
KeysPressed += "True"
ElseIf (e.KeyCode = Keys.Delete) Then
KeysPressed += "True"
End If
If (KeysPressed.IndexOf("True
e.Handled = True
End If
End Sub
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv
If (e.Control And e.Alt And e.KeyCode = Keys.Delete) Then
e.Handled = True
MessageBox.Show("Handled")
End If
End Sub
Neither of these will handle multiple keys pressed at once. They both handle them in the order they occur. Any help would be great! Thanks!
Strickdd
It's because your If statement will fall into the first condition only...
You want it to evaluate each, not just the first that is true...
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles MyBase.KeyDown
If (e.Control) Then KeysPressed += "True"
If (e.Alt) Then KeysPressed += "True"
If (e.KeyCode = Keys.Delete) Then KeysPressed += "True"
If (KeysPressed.IndexOf("True TrueTrue") ) Then
e.Handled = True
End If
End Sub
Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv
If (e.Control) Then KeysPressed += "True"
If (e.Alt) Then KeysPressed += "True"
If (e.KeyCode = Keys.Delete) Then KeysPressed += "True"
If (KeysPressed.IndexOf("True
e.Handled = True
End If
End Sub
The Ctrl-Alt-Del combination is a "secure attention sequence" (SAS) and cannot be prevented on the newer Windows operating systems (NT, 2000, XP) without completely replacing Gina.Dll.
See here for an overview of replacing GINA (Graphical Identification and Authentication):
http://msdn.microsoft.com/msdnmag/issues/05/05/SecurityBriefs/
An alternative is to "disable" it via Policies. See the second question here:
http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/default.aspx
See here for an overview of replacing GINA (Graphical Identification and Authentication):
http://msdn.microsoft.com/msdnmag/issues/05/05/SecurityBriefs/
An alternative is to "disable" it via Policies. See the second question here:
http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/default.aspx
ASKER
Idle_Mind
Is there a way I can change the proper group policy through my code while it is running and then fire an onClose event to reset the policy?
Is there a way I can change the proper group policy through my code while it is running and then fire an onClose event to reset the policy?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Any idea what registry values i have to change?
According to the article...
HKCU\
Software\
Microsoft\
Windows\
CurrentVersion\
Policies\
System\DisableTaskMgr = dword:1
HKCU\
Software\
Microsoft\
Windows\
CurrentVersion\
Policies\
System\DisableTaskMgr = dword:1
ASKER
I'll give that a try and let you know how it goes. Thanks