how to terminate a process?

Miscellaneous Forums/Win32 Discussion/how to terminate a process?

Or here's the BlitzMax conversion:

Extern "Win32"
	Function OpenProcess% (access, handleinherit, processid)
	Function TerminateProcess% (processhandle, exitcode)
	Function CloseHandle% (Objects)
End Extern

Const PROCESS_TERMINATE = $1
Const PROCESS_CREATE_THREAD = $2
Const PROCESS_VM_OPERATION = $8
Const PROCESS_VM_READ = $10
Const PROCESS_VM_WRITE = $20
Const PROCESS_DUP_HANDLE = $40
Const PROCESS_CREATE_PROCESS = $80
Const PROCESS_SET_QUOTA = $100
Const PROCESS_SET_INFORMATION = $200
Const PROCESS_QUERY_INFORMATION = $400
Const SYNCHRONIZE = 1048576
Const STANDARD_RIGHTS_REQUIRED = 983040
Global PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or $FFF)

' This appears To be pretty much how Windows kills a program If you 'End Process'
' from the Task Manager. Note that this is 'unfriendly'!

Function KillProcess (pid)
    phandle = OpenProcess (PROCESS_TERMINATE, False, pid)
    If phandle <> 0
        If TerminateProcess (phandle, 1)
            result = 1
        EndIf
        CloseHandle (phandle)
    EndIf
    Return result
End Function


' ------------------------------------------------------------------------------
' D E M O . . .
' ------------------------------------------------------------------------------
' Enter process ID here! I suggest going To Task Manager,
' making sure PIDs are shown (Try View menu -> Select columns If
' they are Not listed), Then run a program And enter its number here...
' ------------------------------------------------------------------------------

Debuglog KillProcess(-1) ' Change To process ID you want To kill.


However... Like Solitaire asked: Does anyone know how to get the ProcessID? (From within BlitzMax)

More specifically, I'm hoping to find a way to get the process ID for a program that has a slightly dynamic window title, although the name and location of the .EXE itself is known... I do know how to get the hWND's of all running processes, but not how to find the associated PID. I've been looking at the GetWindowThreadProcessId API call, but I must be doing something wrong, since the information it returns to be doesn't seem to match the PIDs listed in the task manager...

Any help would be much appreciated.