Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
----module over
---class
Option Explicit
Public Function KillApp(ByVal WinAppName As String) As Boolean
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, WinAppName)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
KillApp = False
Exit Function
End If
Else
KillApp = False
Exit Function
End If
KillApp = True
End Function
----class over
create a dll and use it in the project or just create the exe and use it.need to pass hte tittle of the application.
test with notepad or calculator application
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.