locked
How to disable ALT+F4,ALT+Esc, Windows Button in VB 2010 express RRS feed

  • Question

  • Dear All,

    Good day!

    I am new to this VB 2010Express programming. Looking for help from those expert on how to disable ALT+F4,ALT+Esc, Windows Button in VB2010 Express.

     

    Tq and BR

    Sunday, August 14, 2011 6:42 AM

Answers

  • You can stop alt+f4 by handling the FormClosing event:

     

    Private Sub frmMyform_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim Cancel As Boolean = eventArgs.Cancel
        Dim UnloadMode As System.Windows.Forms.CloseReason = eventArgs.CloseReason
        If UnloadMode = CloseReason.UserClosing Then
    	  'Prevent it closing
          Cancel = True
        End If
    	
    	'Allow it to close if it wasn't the user's action
        eventArgs.Cancel = Cancel
    End Sub
    

     

    Don't except to stop the other keys working. If you could do that then your app would wreck Windows and people would have to reboot when your program has a problem. They'd also get irritated when those hotkeys that usually work 99.99% of the time are always broken when your app is running.

     

    Monday, August 15, 2011 2:30 AM
  • As a beginner programmer, you really shouldn't be messing with those hotkeys. In any case, it should not be necessary to disable such keys in a windows application - this is more of an administration function on administered machines (I believe such things can be set through administrative policies, so is not really a programming question).

    Do you have any further details about what you want to achieve? Perhaps there's a better way than simply disabling/breaking a users keyboard.


    Stephen J Whiteley
    Monday, August 15, 2011 6:07 PM

All replies

  • You can stop alt+f4 by handling the FormClosing event:

     

    Private Sub frmMyform_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim Cancel As Boolean = eventArgs.Cancel
        Dim UnloadMode As System.Windows.Forms.CloseReason = eventArgs.CloseReason
        If UnloadMode = CloseReason.UserClosing Then
    	  'Prevent it closing
          Cancel = True
        End If
    	
    	'Allow it to close if it wasn't the user's action
        eventArgs.Cancel = Cancel
    End Sub
    

     

    Don't except to stop the other keys working. If you could do that then your app would wreck Windows and people would have to reboot when your program has a problem. They'd also get irritated when those hotkeys that usually work 99.99% of the time are always broken when your app is running.

     

    Monday, August 15, 2011 2:30 AM
  • As a beginner programmer, you really shouldn't be messing with those hotkeys. In any case, it should not be necessary to disable such keys in a windows application - this is more of an administration function on administered machines (I believe such things can be set through administrative policies, so is not really a programming question).

    Do you have any further details about what you want to achieve? Perhaps there's a better way than simply disabling/breaking a users keyboard.


    Stephen J Whiteley
    Monday, August 15, 2011 6:07 PM
  • Dear Huzbuzza, Sjwhiteley,

    Good day!

    Thank you both of you for the Information. But it only can disable ALT+F4, but not function on ALT+Esc & Windows button.

    By the way, i need this function for my kiosk application assignment.

    Now, my kiosk application load maximize and i want it shutdown by special button click. Meanwhile, i need to disable ALT+F4,ALT+ESC,windows button as the requirement of the assignment.

     

     

    Wednesday, August 17, 2011 7:08 AM
  • I recommend you do a Google search on Kiosk applications. There are various options: registry entries, keyboard hooks and simply removing the keyboard (quite feasible in a kiosk application, which removes physical access to those keys).

    A quick search results in this.

    I'm not a big fan of such requirements, and especially consider it very bad instruction to ask this as an assignment (not unusual, thee days). Such tasks are usually done by people who know what they are doing, and are aware of the serious security implications of designing a kiosk application.


    Stephen J Whiteley
    Wednesday, August 17, 2011 11:48 AM