AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ExitApp When All Instances of Chrome Close

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Voltron43



Joined: 27 Mar 2009
Posts: 76
Location: Dublin, IE

PostPosted: Sat Oct 10, 2009 2:22 am    Post subject: ExitApp When All Instances of Chrome Close Reply with quote

I'm building another ChromeLoader for ChromePortable and the idea is as follows:
    -An icon shows in the system tray when ChromeLoader is launched along with an instance of ChromePortable
    -Double clicking the icon in the system tray launches another ChromePortable window
    -Relaunching the original ChromeLoader opens another ChromePortable window but has only one system tray icon.
    -Closing all instances of the ChromePortable causes the ChromeLoader to exit.
    -Exiting ChromeLoader closes all instances of ChromePortable

My problem lies within keeping track of the PID of each instance of ChromePortable. I want to be able to keep all other local instances of Chrome running while closing only the portable instances.

The current code works fine with one instance of ChromePortable, but once ChromeLoader is launched again, the script exits.

What's the best way to close ChromeLoader only when all other instances of ChromePortable are closed? (A local instance of Chrome can still be running).

Code:
...

Run, chrome.exe,,, PID
    Loop
        If ProcessExist(PID) = 0, Break
    ExitApp

ProcessExist(PID)   {
    Process, Exist, %PID%
    Return, ErrorLevel
}

...

_________________
My Scripts
Back to top
View user's profile Send private message Visit poster's website
toralf n-l-i
Guest





PostPosted: Sat Oct 10, 2009 10:12 am    Post subject: Reply with quote

Hi,

First of all, I would recommend to use a Timer (command: SetTimer) instead of a loop.

Then the solution could be to store a list of PIDs in a static variable in a function.
1) When the function is called with a PID it gets added to the var.
2) When the function gets called without a PID it loops over the var and checks if the PIDs are running, if not it removes the PID from the var.
When the var gets empty, the function returns 1 to show that all PID have exit.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group