Micro Focus QTP (UFT) Forums
Close all IE browsers - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Close all IE browsers (/Thread-Close-all-IE-browsers)



Close all IE browsers - bend0303 - 01-22-2012

Hi,
im trying to use WMI to close all browsers.
thats my function:

Code:
Sub CloseAllBrowsers()    
    strSQL = "Select * From Win32_Process Where Name = 'iexplore.exe'"

    Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set ProcColl = oWMIService.ExecQuery(strSQL)

    For Each oElem in ProcColl
        oElem.Terminate
    Next

    Set oWMIService = Nothing
End Sub

problem is that when it finish closing the browsers it perform another iteration and poping an error that oElem was not found (see attachment)

Thank you so much!


RE: Close all IE browsers - vIns - 01-22-2012

Hi..i was also using this approach to close the browsers. I used to get same error some times. I dont think u would get this everytime u run...

Then i started using below method which works gr8 w/o any issue.. I am not sure of your requirement. If u just need to close all IEs, try this.
SystemUtil.CloseProcessByName("iexplore.exe")


RE: Close all IE browsers - Ankesh - 01-23-2012

Hi,

You can use the below function. This will close any process running in task bar. All you need to do is to pass the process name.

Code:
Public Function CloseProcess(strProgramName)
   Dim objShell
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "TASKKILL /F /IM " & strProgramName
    Set objShell = Nothing
End Function
Regards,
Ankesh