cybermoonlight
asked on
closing apps
wonmdering what api to call in order to close all running apps?
thanks
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi cybermoonlight,
Here is another samples:
'Close an application using the API.
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub cmdClose_Click()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, Text1.Text)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "Error posting message."
End If
Else
MsgBox Text1.Text + " is not open."
End If
End Sub
__________________________ __________ __________
Obtaining a List of Running Processes:
http://www.mvps.org/vbnet/code/system/toolhelpprocesses.htm
Compare your exe path with the processes running.
__________________________ __________ __________
Useful links:
http://www.mvps.org/vbnet/faq/main/getmodulehandle.htm
http://www.mvps.org/vbnet/code/system/toolhelpprocesses.htm
http://www.mvps.org/vbnet/faq/main/getexitcodeprocess.htm
http://www.mvps.org/vbnet/faq/main/getmoduleusage.htm
'Hope will help.
Here is another samples:
'Close an application using the API.
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub cmdClose_Click()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, Text1.Text)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "Error posting message."
End If
Else
MsgBox Text1.Text + " is not open."
End If
End Sub
__________________________
Obtaining a List of Running Processes:
http://www.mvps.org/vbnet/code/system/toolhelpprocesses.htm
Compare your exe path with the processes running.
__________________________
Useful links:
http://www.mvps.org/vbnet/faq/main/getmodulehandle.htm
http://www.mvps.org/vbnet/code/system/toolhelpprocesses.htm
http://www.mvps.org/vbnet/faq/main/getexitcodeprocess.htm
http://www.mvps.org/vbnet/faq/main/getmoduleusage.htm
'Hope will help.
http://www.freevbcode.com/ShowCode.Asp?ID=2781
http://www.vbapi.com/ref/w/wm_close.html
http://www.vbapi.com/ref/d/destroywindow.html
http://www.vbweb.co.uk/show.asp?id=146
They either kill a process, or a window (close / destroy).
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Call SendMessage(hWnd, WM_CLOSE, 0, 0)
Where hWnd is the handle of the window to close.
http://www.mvps.org/vbnet/index.html?code/subclass/shellnotifybasic.htm
That link will show how to enumerate all windows and child windows.