Link to home
Start Free TrialLog in
Avatar of strickdd
strickddFlag for United States of America

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.KeyEventArgs) 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("TrueTrueTrue")) Then
            e.Handled = True
        End If
    End Sub



Private Sub Form_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
Avatar of pauljk1619
pauljk1619

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.KeyEventArgs) 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("TrueTrueTrue")) Then
            e.Handled = True
        End If
    End Sub
Avatar of Mike Tomlinson
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

Avatar of strickdd

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?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any idea what registry values i have to change?
According to the article...

HKCU\
 Software\
  Microsoft\
   Windows\
    CurrentVersion\
     Policies\
      System\DisableTaskMgr = dword:1
I'll give that a try and let you know how it goes. Thanks