Terminate a running application
Terminate a running application
(OP)
This is driving me crazy. I've searched the internet and found APIs that supposedly terminate an application but none work....or I can't get them to work such as TerminateProcess and Shell with a parameter to Terminate but I can't get either to work. I found one where I was expected to pass the cursor position!
Anyway, what I want to do is have an application that will terminate another running program in VB 6. Please help!
Anyway, what I want to do is have an application that will terminate another running program in VB 6. Please help!
RE: Terminate a running application
lcNameExe = ['AcroRd32.exe']
loCIMV2 = GetObject("winmgmts://localhost/root/cimv2")
loProcesses = loCIMV2.ExecQuery("SELECT * FROM Win32_Process WHERE Name = " + ['AcroRd32.exe'])
IF loProcesses.Count > 0
For Each objProcess in loProcesses
objProcess.Terminate(0)
NEXT
ENDIF
RE: Terminate a running application
in a module;
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Sub CloseProg(WinTitle$)
Dim lret As Long
lret = FindWindow(0&, WinTitle$)
If lret Then EndTask lret
End Sub
Private Function EndTask(ByVal TargetHwnd&) As Boolean
If IsWindow(TargetHwnd) Then
If Not (GetWindowLong(TargetHwnd, GWL_STYLE) And WS_DISABLED) Then
PostMessage TargetHwnd, WM_CANCELMODE, 0, 0&
PostMessage TargetHwnd, WM_CLOSE, 0, 0&
EndTask = True
End If
End If
End Function
RE: Terminate a running application
Public Const GWL_STYLE = (-16)
Public Const WS_DISABLED = &H8000000
Public Const WM_CLOSE = &H10
Public Const WM_CANCELMODE = &H1F
RE: Terminate a running application
That really does kill it....But it made me think of something else.....is there a way for it to wait/check and see if the application I want to terminate is currently processing a job before ending it?
Thanks again for the absolutley great code! You didn't give me anything vaue what-so-ever and I really appreciate it.
I'll give Zografski's suggestion a try too and see what that does!
RE: Terminate a running application