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
LVL 28
strickddAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I've verified that the policy change does work on my WinXP Pro SP2 system but I did it manually with the Group Policy editor.

I imagine it would work by adding/changing the correct registry keys via code but I haven't tried it myself.

You would use the RegistryKey() class:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfMicrosoftWin32RegistryKeyClassTopic.asp
0
 
pauljk1619Commented:
It's because your If statement will fall into the first condition only...
0
 
pauljk1619Commented:
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
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

0
 
strickddAuthor Commented:
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?
0
 
strickddAuthor Commented:
Any idea what registry values i have to change?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
According to the article...

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.