Results 1 to 6 of 6

Thread: [RESOLVED] Terminating a Process

  1. #1

    Thread Starter
    Lively Member Moneybucks's Avatar
    Join Date
    Apr 2006
    Location
    Kingston Upon Thames -UK
    Posts
    123

    Resolved [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

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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:
    1. 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

  3. #3

    Thread Starter
    Lively Member Moneybucks's Avatar
    Join Date
    Apr 2006
    Location
    Kingston Upon Thames -UK
    Posts
    123

    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

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Terminating a Process

    Quote 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

  5. #5
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    Re: Terminating a Process

    Quote 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.

  6. #6

    Thread Starter
    Lively Member Moneybucks's Avatar
    Join Date
    Apr 2006
    Location
    Kingston Upon Thames -UK
    Posts
    123

    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
  •  



Click Here to Expand Forum to Full Width