How do i close an application started with shell command
Printable View
How do i close an application started with shell command
I came accross this before but unfortunately I can't remember the exact syntax.
You need to use an API (possibly SetWindowPos, I can't remember) to set the window size to 0,0. This closes the window and therefore ends the application.
I couldn't find a more direct way of doing it.
Good luck.
Best regards,
Rob Brown.
Code:
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
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 Declare Function DestroyWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim hApp As Long
hApp = FindWindowEx(0&, 0&, vbNullString, "Notepad")
If hApp <> 0 Then
SendMessage hApp, WM_CLOSE, 0, 0
DestroyWindow hApp
End If
End Sub