|
-
Sep 3rd, 2005, 02:15 PM
#1
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
#2
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.
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
|