|
-
Apr 20th, 2007, 05:56 AM
#1
Thread Starter
Lively Member
[RESOLVED] Terminating a Process
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.
If, somehow, I help you, please rate the post using the scales icon in the left bar <----  .
Please Use Naming Conventions in your projects! ------\/
http://www.visibleprogress.com/vb_na...onventions.htm
Me to Brother
-Hey, look at this avater I made in about 5 seconds
-What, morrisons?
-AGHHHHHH
-
Apr 20th, 2007, 06:11 AM
#2
Re: Terminating a Process
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
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 20th, 2007, 06:15 AM
#3
Thread Starter
Lively Member
Re: Terminating a Process
How would I get the process ID then, another API?
If, somehow, I help you, please rate the post using the scales icon in the left bar <----  .
Please Use Naming Conventions in your projects! ------\/
http://www.visibleprogress.com/vb_na...onventions.htm
Me to Brother
-Hey, look at this avater I made in about 5 seconds
-What, morrisons?
-AGHHHHHH
-
Apr 20th, 2007, 06:20 AM
#4
Re: Terminating a Process
 Originally Posted by Moneybucks
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?
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 20th, 2007, 09:50 PM
#5
Lively Member
Re: Terminating a Process
 Originally Posted by Moneybucks
How would I get the process ID then, another API?
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.
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.
-
Apr 21st, 2007, 12:05 PM
#6
Thread Starter
Lively Member
Re: Terminating a Process
Managed to do what i wanted, with a combination of you two and MSDN, Thanks.
If, somehow, I help you, please rate the post using the scales icon in the left bar <----  .
Please Use Naming Conventions in your projects! ------\/
http://www.visibleprogress.com/vb_na...onventions.htm
Me to Brother
-Hey, look at this avater I made in about 5 seconds
-What, morrisons?
-AGHHHHHH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|