Luc
Well-known member
- Joined
- Nov 29, 2005
- Messages
- 59
- Programming Experience
- 1-3
I'm trying to be able to close processes in my application but he's never able to find the window handle, i would appreciate anny help.
declaration: (copy pasted this from a site and read a tutorial on how to use it)
this goes in my button:
declaration: (copy pasted this from a site and read a tutorial on how to use it)
[FONT="] Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer[/FONT]
[FONT="] Private Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer[/FONT]
[FONT="] Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer[/FONT]
[FONT="] Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer[/FONT]
[FONT="] Private Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Integer, ByVal uExitCode As Integer) As Integer[/FONT]
[FONT="] Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer[/FONT]
[FONT="] Private Const SYNCHRONIZE As Integer = &H100000[/FONT]
[FONT="] Private Const PROCESS_TERMINATE As Integer = &H1[/FONT]
[FONT="] Private Const WM_CLOSE As Integer = &H10 '[/FONT]
this goes in my button:
ThxDim hndl, proc_ID, proc_hndl As Integer
hndl = FindWindow(vbNullString, "explorer")
If hndl = 0 Then MessageBox.Show("Couldn't find") : Exit Sub
proc_ID = 0
GetWindowThreadProcessId(hndl, proc_ID)
If proc_ID = 0 Then MessageBox.Show("proc_ID error") : Exit Sub
proc_hndl = OpenProcess(SYNCHRONIZE Or PROCESS_TERMINATE, 0, proc_ID)
If proc_hndl = 0 Then MessageBox.Show("proc hndlr fout!") : Exit Sub
If (TerminateProcess(proc_hndl, 0) = 0) Then
MessageBox.Show("Failed to close")
Else
MessageBox.Show("Closed")
End If
CloseHandle(proc_hndl)