Sign in to follow this  
Followers 0
Chorda

ProcessClose() does not close

8 posts in this topic

Hmm this one puzzles me...

I have two processes with the same name (miranda32.exe) and my script only closes one. In order to close both I have to open a msgbox in my loop.

CODE
For $AppCounter = 1 To $AppList[0] ; list of all my processes

; $Executable includes the entire path

$Executable = $AppExecutable[$AppCounter] ;

; $Process is the name of the executable. Remove the whole path and keep the .exe

$Process = StringReplace($Executable,StringLeft($Executable,StringInStr($Executable,"\",0,-1)),"")

$PID = ProcessExists($Process)

;msgbox(0, "Closing Programs", "Closing " & $Process)

If $PID Then ProcessClose($Process)

Next

So, when this msgbox is there, both processes are closed. But as soon as I comment out the msgbox, only one of the two processes is closed. I also tried changing $Process by $PID in If $PID Then ProcessClose($Process), but it does not work either. (I've also tried a bunch of other things).

Thanks

Share this post


Link to post
Share on other sites



try adding a sleep where the msgbox is something like

Sleep(10)

may be sufficient, but i dont know try and find a value that works 100 should be ok if 10 doesnt work but it depends how many processes you have how long the time to close them all would be if you have a high sleep value, but as i said find one that works. if its only 2 processes then just use 100 or maybe more. take into account that 1000 is 1 second


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites

how about something like this?

#include <Process.au3>

$procname = "notepad.exe"

$winlist = WinList()
For $i = 1 to $winlist[0][0]
    $pid = WinGetProcess($winlist[$i][1])
    If _ProcessGetName($pid) = $procname Then ProcessClose($pid)
Next

Share this post


Link to post
Share on other sites

Got it. I had tried with a Sleep(2000), but it didn't seem to work that well. So since it is that processes take whatever time they need to close, I just added a while loop like this:

If $PID Then ProcessClose($Process)

While ProcessExists($PID)

WEnd

So, now it just waits until the process has terminated.

Thanks a lot for pointing that out.

Share this post


Link to post
Share on other sites

I think a prob also is hat you re calling Process exists against a string (miranda32.exe). It can be unreliaable when multiple instances are running. However WinList() returns Handles ([n][1]) instead which are unique.

Share this post


Link to post
Share on other sites

You can use ProcessList("miranda32.exe") to return an array of all processes of that name.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Hi there.

ProcessClose only works with processes open with the same user name that is running the sript for now.

Bug 501 solved in beta 3.2.13.8

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


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