Jump to content

Closing all open web browsers...


mdwerne
 Share

Recommended Posts

I'm working on a Java cleanup utility and one of the first steps is to close all open browsers. Firefox, Opera, Chrome and Safari all close and re-open without issue...but IE 8 generates an error when I re-open it stating "Your last browsing session closed unexpectedly" the two options are "Restore your last session" or "Go to your home page"

Here is the close code I've tried...all variations give me the same error on re-launch of IE.

Does anyone have a suggestion as to how I can close IE (and all open IE tabs) gracefully?

Thanks for your time,

-Mike

Func CloseApps()
    $CloseApps = GUICtrlCreateLabel("Closing Java and all Internet Browsers, please wait...", 300, 330, 450, 25)
    GUICtrlSetFont(-1, 12, 800, 0, "Georgia")
    GUICtrlSetColor(-1, 0xFF0000)

    ;CLOSE JAVA
    While ProcessExists("jqs.exe")
        ProcessClose("jqs.exe")
    WEnd

    While ProcessExists("Javaw.exe")
        ProcessClose("Javaw.exe")
    WEnd

    While ProcessExists("Java.exe")
        ProcessClose("Java.exe")
    WEnd

    ;CLOSE BROWSERS
    Dim $aIE[1]
    $aIE[0] = 0
    Dim $i = 1
    While 1
        Dim $oIE = _IEAttach("", "instance", $i)
        If @error = $_IEStatus_NoMatch Then ExitLoop
        ReDim $aIE[$i + 1]
        $aIE[$i] = $oIE
        $aIE[0] = $i
        $i += 1
        _IEQuit($oIE)
    WEnd

;~  While 2
;~      If ProcessExists("IEXPLORE.exe") Then
;~          ProcessClose("IEXPLORE.exe")
;~      EndIf
;~      If Not ProcessExists("IEXPLORE.exe") Then
;~          ExitLoop
;~      EndIf
;~  WEnd

;~  While 1
;~      ProcessClose("iexplore.exe")
;~      Global $pid = ProcessExists("iexplore.exe")
;~      If $pid Then ProcessClose($pid)
;~  WEnd

    While ProcessExists("Iexplore.exe")
        ProcessClose("Iexplore.exe")
    WEnd

    While ProcessExists("Firefox.exe")
        ProcessClose("Firefox.exe")
    WEnd

    While ProcessExists("Safari.exe")
        ProcessClose("Safari.exe")
    WEnd

    While ProcessExists("Chrome.exe")
        ProcessClose("Chrome.exe")
    WEnd

    While ProcessExists("Opera.exe")
        ProcessClose("Opera.exe")
    WEnd
    Sleep(3000)
EndFunc   ;==>CloseApps
Link to comment
Share on other sites

Don't close the process. You should _IEAttach() in a loop and do _IEQuit() on each instance instead.

:)

So this is ugly, but it seems to work.

#include <IE.au3>
While ProcessExists("Iexplore.exe")
    GetIE()
WEnd
Exit

Func GetIE()
    Dim $aIE[1]
    $aIE[0] = 0
    $i = 1

    While 1
        $oIE = _IEAttach("", "instance", $i)
        If @error = $_IEStatus_NoMatch Then ExitLoop
        ReDim $aIE[$i + 1]
        $aIE[$i] = $oIE
        $aIE[0] = $i
        $i += 1
        _IEQuit($oIE)
        sleep(500)
    WEnd
EndFunc   ;==>GetIE

One side affect is that I get this warning from the console.

--> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch

Thanks for the suggestion...

-Mike

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...