how can i close another program from my program. i used the closewindow api but it didnt work.
Printable View
how can i close another program from my program. i used the closewindow api but it didnt work.
You Should try to use tanother API here is one that works fine with me : (warning - It c loses any application u specify without asking save yes/no/cancel)
Declarations :Code:Public Sub ForceAppClosed(ByVal lHwnd As Long) 'Force the App to Shutdown
Dim lPID As Long
Dim lCode As Long 'Get the Windows ProcessID
Call GetWindowThreadProcessId(lHwnd, lPID) 'Get a Handle to the Process
lPID = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPID) 'Get the Processes Exit Cod
Call GetExitCodeProcess(lPID, lCode) 'Tell the Process to Terminate
Call TerminateProcess(lPID, lCode)
End Sub
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, 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 GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
You Should try to use tanother API here is one that works fine with me : (warning - It c loses any application u specify without asking save yes/no/cancel)
Declarations :Code:Public Sub ForceAppClosed(ByVal lHwnd As Long) 'Force the App to Shutdown
Dim lPID As Long
Dim lCode As Long 'Get the Windows ProcessID
Call GetWindowThreadProcessId(lHwnd, lPID) 'Get a Handle to the Process
lPID = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPID) 'Get the Processes Exit Cod
Call GetExitCodeProcess(lPID, lCode) 'Tell the Process to Terminate
Call TerminateProcess(lPID, lCode)
End Sub
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, 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 GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Hi,
I have tried your way to close apps which are started with shell32 commnad. It works for most applications but not for Miscrosoft Imaging, where I found process ID will be reset to zero when OpenProcess is run.
Pls advise.
Brgds,/Albert