Thursday, August 18, 2011

Closes all instatnces of open IE browsers

Function Close_All_Browsers()

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colIEProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")

For Each objProcess in colIEProcessList
objProcess.Terminate()
Next
End Function

5 comments:

  1. Why is that much procedure needed to close all the opened IE browsers

    Use simply -
    SystemUtil.CloseByProcessName "iexplore.exe"

    that's it..

    ReplyDelete
  2. You r Correct Sreenu.
    But if you want to write your own method to close this is the way.

    ReplyDelete
  3. I use • Close all IE browsers: SystemUtil.CloseProcessByName("iexplore.exe")

    ReplyDelete
  4. Both are different.
    SystemUtil.CloseProcessByName("iexplore.exe")
    It will throw a validation error if no instances are open in the above case.

    But if the mentioned function is used. it will close all/any open instances .

    ReplyDelete