Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long Private Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "Kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Const SYNCHRONIZE = &H100000 Private Const PROCESS_TERMINATE As Long = &H1 Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Const WM_CLOSE As Long = &H10 ' Terminate the process. Private Sub cmdTerminate_Click() Dim target_hwnd As Long Dim target_process_id As Long Dim target_process_handle As Long ' Get the target's window handle. target_hwnd = FindWindow("Internet Explorer_Hidden", vbNullString) If target_hwnd = 0 Then MsgBox "Error finding target window handle" Exit Sub End If ' Get the process ID. GetWindowThreadProcessId target_hwnd, target_process_id If target_process_id = 0 Then MsgBox "Error finding target process ID" Exit Sub End If ' Open the process. target_process_handle = OpenProcess( _ SYNCHRONIZE Or PROCESS_TERMINATE, _ ByVal 0&, target_process_id) If target_process_handle = 0 Then MsgBox "Error finding target process handle" Exit Sub End If ' Terminate the process. If TerminateProcess(target_process_handle, 0&) = 0 Then MsgBox "Error terminating process" Else MsgBox "Process terminated" End If ' Close the process. CloseHandle target_process_handle End Sub