What API would I need to use to terminate a process, I know it can be done because I saw it in a book once, but I can't find it now.
Printable View
What API would I need to use to terminate a process, I know it can be done because I saw it in a book once, but I can't find it now.
You are looking for TerminateProcess API. You need to know ProcessID of the process that you want to terminate.
vb Code:
Public Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
How would I get the process ID then, another API?
Which process do you want to terminate? How are you launching this process if it is owned by you?Quote:
Originally Posted by Moneybucks
To get the PID of another process, you need a different Identifier. So lets say you want to terminate a process by its Image Name, then you need to create a loop using a Process Enum either by a ProcessSnapshot or EnumProcesses API.Quote:
Originally Posted by Moneybucks
Depending on the order of your loop that you search for the exe based on PID, will determine if the most resent Image Name is terminated or the oldest. Or you can have the process loop cycle through all of the processes and for every exe name that matches, have it terminate it.
A good function for this would be something like:
Public Function GetPID (ByVal sProcessName as String) as Long
Good Luck.
Managed to do what i wanted, with a combination of you two and MSDN, Thanks.