Forum Discussion

mazhar555's avatar
mazhar555
Contributor
15 years ago

Closing Internet Explorer

HI, i have written a routine to close all IE Instances before launching a new IE instance, this function is in the Script Extension, some times it works fine sometimes it throws VB Exception, can anyone suggest me some better solution.



Function CloseAllBrowser

    IExplore = Sys.FindAllChildren("ProcessName","iexplore",2)

     If UBound(IExplore)>=0 Then

  For i = 0 to UBound(IExplore)

           IExplore(i).Terminate

        Next

 End If

End Function



Regards,
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    While (Sys.WaitProcess("iexplore",0).Exists) 'Wait process prevents error if not existing


     Sys.Process("iexplore").Terminate 'Terminate process


     Sys.Refresh 'Refresh object tree


    Wend



    Or if you want a more elegant method not requiring test complete:



    ProcessKill("iexplore")




    Sub ProcessKill(strProcessKill)


    strComputer = "."


    Set objWMIService = GetObject("winmgmts:" _


        & "{impersonationLevel=impersonate, " _


        & "(Debug)}!\\" _


        & strComputer & "\root\cimv2")


    Set colProcess = objWMIService.ExecQuery _


    ("Select * from Win32_Process Where Name = " & strProcessKill)


    For Each objProcess in colProcess


     objProcess.Terminate()


    Next


    End Sub




  • Anonymous's avatar
    Anonymous
    This just helped me enormously!  Thank you!
  • I use this routine:

    Sub CloseIexplore()
    Indicator.Clear
    Indicator.PushText("Close iexplorer")

    comando = "taskkill /f /im iexplore.exe"
    set cmd = sys.OleObject("WScript.shell")
    call cmd.Run(comando)
    Indicator.Clear
    End Sub

    After execution I start iexplorer and close again to clean the windows that appear with the information that the iexplorer was not close ok.