[RESOLVED] More powerful than API TerminateProcess...
I've tested API TerminateProcess and it did not kill some programs like
"Warcraft 3 Frozen Throne" as far as i knew the program is not running as
service...why? is there any other way which is more powerfull to kill a process
like the one program i mentioned above...thanks
Re: More powerful than API TerminateProcess...
I don't have VB6 with me right now, but stick this in a module and try:
VB Code:
Option Explicit
Private 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
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Target As String
Private Const WM_CLOSE = &H10
Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
Dim hWndREC As Long
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length)
If InStr(1, title, Target, 3) <> 0 Then
PostMessage app_hWnd, WM_CLOSE, 0, 0
End If
EnumCallback = 1
End Function
Public Sub CloseProgram(app_name As String)
Target = app_name
EnumWindows AddressOf EnumCallback, 0
End Sub
Call with
CloseProgram("Warcraft 3 Frozen Throne"), or whatever the caption is in the toolbar.
Re: More powerful than API TerminateProcess...
Works Great thanks...
but another problem comes up...because i want to programatically kill some processes that way, i dont know how to enumerate the caption of each process that is on the taskbar so that i can pass each caption to closeprogram...can you show me how...thank you very very much.
Re: More powerful than API TerminateProcess...
I'm not sure what you mean.. do you want to end every process with this function?
Re: More powerful than API TerminateProcess...
Why do you need to terminate so many processes?
Re: More powerful than API TerminateProcess...
Ok, this is what i mean...
At a certain amount of time, my app should kill some process(a variety of programs) which have been lunch(and was left running) during the session. my app will iterate through a list of that processes and kill each one of them.
And by using the function above, it needs to know the captions of each processes in order to kill it, right.
Thats where my problem arise, i have to enumerate and make a list of the "captions" of that variety of running processes, how would i get that "captions" programatically...
(im pretty sure its not the exe name)
i hope you understand my explanation...
Re: More powerful than API TerminateProcess...
Umm, no. You can Terminate a running process just by its exe name.
http://www.vbforums.com/showpost.php...71&postcount=5
And to enumerate the running processes.
http://vbforums.com/showthread.php?t=244232
Re: More powerful than API TerminateProcess...
I think i got your problem(same with mine) and maybe This can help you too.
Re: More powerful than API TerminateProcess...