Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prevent Certain Key Combinations

Posted on 2006-05-16
8
Medium Priority
?
181 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:strickdd
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:pauljk1619
ID: 16692197
It's because your If statement will fall into the first condition only...
0
 
LVL 7

Expert Comment

by:pauljk1619
ID: 16692213
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16693347
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Author Comment

by:strickdd
ID: 16693546
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 16693638
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
 
LVL 28

Author Comment

by:strickdd
ID: 16701102
Any idea what registry values i have to change?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16701123
According to the article...

HKCU\
 Software\
  Microsoft\
   Windows\
    CurrentVersion\
     Policies\
      System\DisableTaskMgr = dword:1
0
 
LVL 28

Author Comment

by:strickdd
ID: 16701480
I'll give that a try and let you know how it goes. Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question