Results 1 to 19 of 19

Thread: How to prevent ALt+F4

  1. #1

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    How to prevent ALt+F4

    im making a computer locking program which makes you enter a password to close it...

    i need to prevent the user from pressing ALT + F4... I tried simply modifying the keypress event but it isnt working... why? do i need to use an api or somthing?

    VB Code:
    1. Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, Me.KeyDown
    2.         If e.KeyData = Keys.Enter Then
    3.             e.SuppressKeyPress = True
    4.             If TextBox1.Text = pas Then
    5.                 Me.Close()
    6.             End If
    7.         End If
    8.  
    9.         If e.Modifiers = Keys.Control + Keys.F4 Then
    10.             e.SuppressKeyPress = True
    11.         End If
    12.     End Sub

  2. #2

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    oops.... replace keys.control with keys.alt.... (it still doesnt work, tho)

  3. #3

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    hmm.. well i fixed it by doing this:

    VB Code:
    1. If e.Alt Or e.Control Or e.KeyData = Keys.Delete = True Then
    2.             e.SuppressKeyPress = True
    3.             e.Handled = True
    4.         End If

    but how do i disable CTRL + ALT + DEL?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to prevent ALt+F4

    I may be wrong, but I have not seen any code that can do that yet. Its protected and it deals with the security dll - msgina.dll

    Why do you need to prevent it? Maybe there is a workaround.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    well im making a custom locked computer screen... i have sucessfully prevented alt f4.... but ctrl alt del still works

  6. #6

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    is it possible to do it via batch file or somthing?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to prevent ALt+F4

    I dont know but I have read a few posts about creating your own desktop for something like what your doing and try a search for them. I think they were creating their own explorer shellor something. Its easier and helps to contain everything in that shell.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    ooh i figured it out....

    i made a timer which sent the form to the front constantly, then i made a sub which gives it focus if it loses focus... so it goes in front of the task manager!

    yay

  9. #9
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: How to prevent ALt+F4

    I have 'sort of' prevented ctrl+alt+del with an expirment or prototype for my last boss for a kiosk which was supposed be just a normal app but to lock out the user completely (assuming also they could not turn off the computer, not in same location as keyboard mouse etc)

    i continously did this

    Me.Show()
    Me.SetTopLevel(True)
    Me.Activate()

    on the form, they r able to use ctrl+alt+del but it's rendered useless as they cant click anything on it, i cant remember but i did work out a few shortcut keys that still work in it

    remember to use ctrl+pausebreak to end the project after you test this and don't run the exe

  10. #10
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: How to prevent ALt+F4

    Oh, you did the same thing anyway

  11. #11

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: How to prevent ALt+F4

    ya, except mine doesnt flicker... you have to put a me.focus() under the formlostfocus event and then make a timer that does me.bringtofront()....
    and it has to be a topmost form

  12. #12
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: How to prevent ALt+F4

    disabletskmgr registry key. See article half way down this page:
    http://www.devcity.net/newsletter/ar...ty20050715.htm

    If you wanted to trap ctrl-alt-delete you would have to use msgina.dll, and you need to be able to use pointers properly (like in c++) - so you can't do it in c# or vb.net.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to prevent ALt+F4

    I thought someone could shed some light on this. Thanks for the link and I was right too about the msgina.dll.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Resolved Re: How to prevent ALt+F4

    well i have gotten it to work by forcing the window to always have focus and be ontop... so it goes ontop of the taskmanager rendering it useless... and i already disabled ALT+F4....
    yay!

  15. #15
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    detect ctrl alt delete

    Code:
    Imports System.Drawing
    Imports System.Threading
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Friend Class Form1
        Inherits System.Windows.Forms.Form
    #Region " Windows Form Designer generated code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
    
        End Sub
    
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer. 
        'Do not modify it using the code editor.
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents Button2 As System.Windows.Forms.Button
    
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.Button1 = New System.Windows.Forms.Button
            Me.Button2 = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(88, 72)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(128, 24)
            Me.Button1.TabIndex = 1
            Me.Button1.Text = "Disable task manager."
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(88, 112)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(128, 24)
            Me.Button2.TabIndex = 2
            Me.Button2.Text = "Enable Task manager"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.Controls.Add(Me.Button2)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "                 Ctrl + Alt + Delete"
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
    
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
        Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
        Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
        Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
        Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
    
        Public Structure KBDLLHOOKSTRUCT
            Public vkCode As Integer
            Public scanCode As Integer
            Public flags As Integer
            Public time As Integer
            Public dwExtraInfo As Integer
        End Structure
    
        Public Delegate Function KeyboardHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        <MarshalAs(UnmanagedType.FunctionPtr)> Private callback As KeyboardHookDelegate
        Public KeyboardHandle As Integer
    
        ' Low-Level Keyboard Constant
        Const HC_ACTION As Integer = 0
    
        ' Virtual Keys
        Const KEYEVENTF_KEYUP As Short = &H2
        Const VK_SHIFT As Integer = &H10
        Const VK_CONTROL = &H11
        Const VK_DELETE = &H2E
        Const VK_MENU = &H12
        Const VK_ESCAPE As Integer = &H1B
        Const WH_KEYBOARD_LL As Integer = 13&
    
    
        'This function allows keys to be detected and dealt with.
        Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean
            On Error Resume Next
    
            ' ctrl alt delete, can be detected here. The task manager is closed.
            If (Hookstruct.vkCode = VK_DELETE) And CBool(GetAsyncKeyState(VK_MENU) And &H8000) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) Then
                Do
                    Application.DoEvents()
                    SendKeys.Flush()
                    Dim clt() As Process = Process.GetProcessesByName("taskmgr")
                    For Each p As Process In clt
    
                        'kill task manager and rip from memory
                        p.Kill()
    
                        'Thanks to Dan Appleman, who doesn't know why either.
                        Application.DoEvents()
                        SendKeys.Flush()
    
                        'Return Task Manager function here, to replace memory.
                        'Simulate Ctrl Shift Esc to call task managers back to duty.
                        keybd_event(VK_CONTROL, 0, 0, 0)
                        keybd_event(VK_SHIFT, 0, 0, 0)
                        keybd_event(VK_ESCAPE, 0, 0, 0)
                        keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0)
                        keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0)
                        keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
                        'END--Ctrl Alt Delete has been essentially blocked here from bringing up the task manager.
                        'If you want to personalize your own application's task manager.
                        'Call MyTaskMangerReplacement(1) 
                        Application.DoEvents()
                        SendKeys.Flush()
                        Exit Do
                    Next
                    Application.DoEvents()
                    SendKeys.Flush()
                Loop
            End If
    
            'disable task manager for, control shift esc.
            If (Hookstruct.vkCode = VK_ESCAPE) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) And CBool(GetAsyncKeyState(VK_SHIFT) And &H8000) Then
                Return True
            End If
    
            Return False
        End Function
    
        'Call this to hook keyboard
        Public Sub HookKeyboard()
            callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
            KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
        End Sub
    
        ' UnhookKeyboard is very important to include in the form's unload.
        Public Sub UnhookKeyboard()
            If (Hooked()) Then
                Call UnhookWindowsHookEx(KeyboardHandle)
            End If
        End Sub
    
        'Indicates hook success.
        Private Function Hooked()
            Hooked = KeyboardHandle <> 0
        End Function
    
        Public Function KeyboardCallback(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            If (Code = HC_ACTION) Then
                If (IsHooked(lParam)) Then
                    Return 1
                End If
            End If
            Return CallNextHookEx(KeyboardHandle, Code, wParam, lParam)
        End Function
    
        Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
            On Error Resume Next
    
            'unhook keyboard control
            UnhookKeyboard()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            HookKeyboard()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            On Error Resume Next
            UnhookKeyboard()
        End Sub
    End Class
    Last edited by TTn; Sep 6th, 2005 at 06:27 AM.

  16. #16
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Re: How to prevent ALt+F4

    this is probably the most malicious piece of code if ever wrote...
    but it will do what you asked... in vista and in XP

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         Me.BringToFront()
    3.         Me.Focus()
    4.         Me.TopMost = True
    5.         Me.Show()
    6.         Me.SetTopLevel(True)
    7.         Me.Activate()
    8.         Me.WindowState = FormWindowState.Maximized
    9.         Try
    10.             killProcess("LogonUI")
    11.             killProcess("taskmgr")
    12.         Catch ex As Exception
    13.             Return
    14.         End Try
    15.     End Sub
    16.  
    17.     Public Sub killProcess(ByRef strProcessToKill As String)
    18.         Try
    19.             Dim proc() As Process = Process.GetProcesses
    20.             For i As Integer = 0 To proc.GetUpperBound(0)
    21.                 If proc(i).ProcessName = strProcessToKill Then
    22.                     proc(i).Kill()
    23.                 End If
    24.             Next
    25.         Catch ex As Exception
    26.             Return
    27.         End Try
    28.    
    29.     End Sub
    How To Make A Youtube Downloader
    I use Visual Studio 2008 Pro...

  17. #17
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: How to prevent ALt+F4

    All of these methods are terrible and will not work if the computer is part of a domain (and thus, CTRL + ALT + DEL jumps to the management screen) or has a sane security policy.

    If you're making a kiosk system you really should not use a consumer or server OS; you should be using an embedded OS (like Windows CE 6). If you're making some sort of locking screen... we'll you're just duplicating OS functionality and since it's not low level enough it means you'll be able to break it in one way or another despite what you do.

    Also, killing processes is very bad. Especially if you're doing it by name as I could have a process called LogonUI that you're application is now killing rather than its true target. Let's not forget that you can't just kill random processes in Vista unless you have the appropriate security level.

    Why was this thread dug from the grave anyway?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  18. #18
    Lively Member wiz....'s Avatar
    Join Date
    Nov 2008
    Location
    Asia, Earth, Solar System, Milky Way Galaxy, Near Andromeda Galaxy, Universe
    Posts
    78

    Re: How to prevent ALt+F4

    Hey Latin4567 !!!!! can u please post the project so that curious people like me can try it out????????

    thanking you in advance,
    wiz....

  19. #19
    Lively Member wiz....'s Avatar
    Join Date
    Nov 2008
    Location
    Asia, Earth, Solar System, Milky Way Galaxy, Near Andromeda Galaxy, Universe
    Posts
    78

    Re: How to prevent ALt+F4

    hey latin4567 !!!!can u post the project for dummies like me????

    thanks in advance,
    wiz....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width