Jump to content
Sign in to follow this  
IamNoob

ProcessExists(), Multiple Process?

Recommended Posts

IamNoob

Hello!

I am working on a script and am Stumped with this, have searched for a little while with no luck

I have a 2 instances of 1 program running, Same exact Process name (myprog.exe), I am trying to end only ONE of the process' and I would like to be able to control WHICH ONE closes. I have tried ProcessClose() but Obviously no real way of controlling that as it just kills the highest PID of the process.

I cannot use RUN to start this program as it is must be started through a different program.

If possible, I would like to be able to have the First process opened left alone, Only the second one closed.

Thanks in advanced for the help! Back to trying to figure this out :blink:

So I seemed to get something with ProcessList(), Here is my Code...

$list = ProcessList("notepad.exe")
$Safe = 2456
for $i = 1 to $list[0][0]
    If $list[$i][1] <> $Safe then
        ProcessClose($list[$i][1])
    EndIf
next

Is there a better way to do it?

Edited by IamNoob

Share this post


Link to post
Share on other sites
omikron48

ProcessClose also accepts pID(s) as a parameter. You can just kill the specific process you want via its pID.

Share this post


Link to post
Share on other sites
ripdad

Maybe

This might help.

The "time started" is what I would go with.


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
IamNoob

Maybe

This might help.

The "time started" is what I would go with.

Hmm, I may have to play with this, I like the idea.

Here is where I am atm, It seems to be working so far. Simply lets you chose which window you want set as safe, gets the PID and closes the rest.

MsgBox(0, "", "Please click the MyProg Window that you DO NOT want to be closed.", "5")
WinWaitActive("MyProg")
$SafePID = WinGetProcess("[active]") 
Msgbox(0, "", "I have recorded " & $SafePID & " as a safe process")
$list = ProcessList("myprog.exe")
for $i = 1 to $list[0][0]
    If $list[$i][1] <> $SafePID then
        ProcessClose($list[$i][1])
    EndIf
next

Anybody see potential problems with this? Better Ideas?

Edited by IamNoob

Share this post


Link to post
Share on other sites
ripdad

That would probably be okay, depending on how and why a duplicate program executes.

I was thinking more like this:

While 1
    Sleep(1000)
    $avRET = _ProcessListProperties('explorer.exe')
    If $avRET[0][0] > 1 Then
        $getTime1 = @YDAY & StringReplace(StringRight($avRET[1][8], 8), ':', '')
        $getTime2 = @YDAY & StringReplace(StringRight($avRET[2][8], 8), ':', '')
        If $getTime1 > $getTime2 Then
            ProcessClose($avRET[1][1])
        Else
            ProcessClose($avRET[2][1])
        EndIf
    EndIf
WEnd

Going by Ascend4nt's post below ...

While 1
    Sleep(1000)
    $prl = ProcessList('explorer.exe')
    If $prl[0][0] > 1 Then ProcessClose($prl[2][1])
WEnd

-updated and cleaned up post-

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
Ascend4nt

ProcessList() lists the programs in the order they were created. No need to do any fancy tricks to figure out when a program was created. Just use ProcessList() and the 1st created one will be first in the list, the last created would be last in the list. Very simple to solve.

Share this post


Link to post
Share on other sites
ripdad

well imagine that. nothing in the helpfile on it.

thats good to know - thanks


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
KaFu

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.