WORKING WITH QTP

TestEveryThinG

Close All Browser

Posted by rajivkumarnandvani on February 5, 2009

‘ This function Close All open Browser
REM *************************************************************************

REM this function close All open browser

Public Function   fn_CloseAllBrowser()
While Browser(“CreationTime:=0”).Exist
Browser(“CreationTime:=0”).Close
Wend
End Function

REM *************************************************************************

Rem another way to close browser here  this function terminate application ‘process

rem like internet explorer exe will close from system process

dim sApplicationExe

sApplicationExe = “iexplore.exe”

Rem call function to close application process

call fn_CloseApplication( sApplicationExe)

REM This function kill the given process exe  through task manager

Public Function  fn_CloseApplication( byval sApplicationExe)
Dim strComputer
Dim objWMIService
Dim colProcesses
Dim objProcess
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)

Set colProcesses = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘”&sApplicationExe&”‘”)
For Each objProcess in colProcesses
objProcess.Terminate()
Next
Set objWMIService = Nothing
Set colProcesses=Nothing
End Function

REM through this function you can close any application process

3 Responses to “Close All Browser”

  1. Dev said

    Hi, Cool stuff. Great work bro……the examples and knowledge you have given is unique, and exceptioal…Thanks for your effort and time.

  2. Thanks Bro… 🙂

    Rajiv

  3. RKN said

    Another method is:

    ***Close all internet explorer windows
    SystemUtil.CloseProcessByName(“iexplore.exe”)

Leave a comment