Jump to content

Getting the PID of a spawned process

Recommended Posts

I have coded a GUI that calls robocopy.exe, and as part of the exit routine of this GUI I want to check if the robocopy process is running. That is easy enough to do, but what if I had multiple instances of robocopy.exe running on the same box.

Question is: How do I ensure programatically that I have ended only my latest instance of robocopy.exe that was created through my compiled GUI.

I want to kill the PID rather than exe name, as I assume the latest PID of Robocopy.exe in task manager will be the latest process correct?

This is what I already code wise:

Dim $Yes = 6, $No = 7

$i_PID = "Robocopy.exe"

    _ProcessGetName ($i_PID)
    If ProcessExists($i_PID) Then
    $Question = MsgBox(262180, "Question?", "Robocopy process still running, end it now?")
        If $Question = $Yes Then
            SplashTextOn("Exited", "Robocopy copy process killed", 220, 30, -1, -1, 17, "", 12)

Are there any UDF's out there that will do the opposite of _ProcessGetName ( $iPID ), meaning getting the PID of the named process...Something like _ProcessGetPID(Name of exe to check)

Any guidance will be much appreciated..


Edited by lyledg
Link to post
Share on other sites

You should already know the PID as your script started it and can manage it ?

$pid1 = Run('robocopy.exe')
$pid2 = Run('robocopy.exe')
$pid3 = Run('robocopy.exe')

If ProcessExists($pid3) Then ProcessClose($pid3)
Link to post
Share on other sites

i think it is a little simpler than your effort

$PID = ProcessExists("notepad.exe"); Will return the PID or 0 if the process isn't found.
If $PID Then ProcessClose($PID)

to be sure that you are closing the correct PID

$PID = Run("notepad.exe"); this should be a unique identifier ( if i am correct )





MHz got there first ( and i was right..lol)

Edited by Valuater


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...