|
-
Sep 3rd, 2005, 09:46 AM
#1
Thread Starter
Addicted Member
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:
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, Me.KeyDown
If e.KeyData = Keys.Enter Then
e.SuppressKeyPress = True
If TextBox1.Text = pas Then
Me.Close()
End If
End If
If e.Modifiers = Keys.Control + Keys.F4 Then
e.SuppressKeyPress = True
End If
End Sub
-
Sep 3rd, 2005, 09:48 AM
#2
Thread Starter
Addicted Member
Re: How to prevent ALt+F4
oops.... replace keys.control with keys.alt.... (it still doesnt work, tho)
-
Sep 3rd, 2005, 09:55 AM
#3
Thread Starter
Addicted Member
Re: How to prevent ALt+F4
hmm.. well i fixed it by doing this:
VB Code:
If e.Alt Or e.Control Or e.KeyData = Keys.Delete = True Then
e.SuppressKeyPress = True
e.Handled = True
End If
but how do i disable CTRL + ALT + DEL?
-
Sep 3rd, 2005, 09:58 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 3rd, 2005, 10:08 AM
#5
Thread Starter
Addicted Member
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
-
Sep 3rd, 2005, 10:10 AM
#6
Thread Starter
Addicted Member
Re: How to prevent ALt+F4
is it possible to do it via batch file or somthing?
-
Sep 3rd, 2005, 10:41 AM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 3rd, 2005, 10:44 AM
#8
Thread Starter
Addicted Member
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
-
Sep 3rd, 2005, 10:52 AM
#9
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
-
Sep 3rd, 2005, 10:54 AM
#10
Re: How to prevent ALt+F4
Oh, you did the same thing anyway
-
Sep 3rd, 2005, 11:02 AM
#11
Thread Starter
Addicted Member
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
-
Sep 3rd, 2005, 11:42 AM
#12
Hyperactive Member
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.
-
Sep 3rd, 2005, 12:07 PM
#13
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 3rd, 2005, 02:15 PM
#14
Thread Starter
Addicted Member
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!
-
Sep 3rd, 2005, 08:51 PM
#15
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.
-
Nov 29th, 2008, 12:28 AM
#16
Lively Member
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:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.BringToFront() Me.Focus() Me.TopMost = True Me.Show() Me.SetTopLevel(True) Me.Activate() Me.WindowState = FormWindowState.Maximized Try killProcess("LogonUI") killProcess("taskmgr") Catch ex As Exception Return End Try End Sub Public Sub killProcess(ByRef strProcessToKill As String) Try Dim proc() As Process = Process.GetProcesses For i As Integer = 0 To proc.GetUpperBound(0) If proc(i).ProcessName = strProcessToKill Then proc(i).Kill() End If Next Catch ex As Exception Return End Try End Sub
-
Nov 29th, 2008, 03:17 AM
#17
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?
-
Dec 18th, 2008, 06:43 AM
#18
Lively Member
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....
-
Dec 18th, 2008, 07:09 AM
#19
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|