|
-
Apr 5th, 2000, 02:26 AM
#1
Thread Starter
Hyperactive Member
how can i close another program from my program. i used the closewindow api but it didnt work.
-
Apr 5th, 2000, 03:50 AM
#2
Hyperactive Member
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)
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
Declarations :
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
-
Apr 5th, 2000, 03:52 AM
#3
Hyperactive Member
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)
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
Declarations :
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
-
Apr 9th, 2000, 01:31 PM
#4
New Member
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
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
|