Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Close all IE browsers
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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!


Attached Files Image(s)
   
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
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")
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Maximize and Close a Browser mv8167 4 16,662 03-26-2023, 03:55 PM
Last Post: Mike B
  Close popup ad windows dustwynn 1 2,961 10-25-2016, 05:57 PM
Last Post: Ankur
  [UFT] Close opened folder robertosalemi 1 3,353 02-10-2016, 07:06 PM
Last Post: robertosalemi
  Close browser code not working akilamurugesh 1 4,640 08-26-2014, 03:21 PM
Last Post: vinod123
  Close on Exit Issue in QTP 11.0 EGBELL 1 3,209 02-02-2014, 03:39 PM
Last Post: EGBELL

Forum Jump:


Users browsing this thread: 1 Guest(s)