TESTEVERYTHING

Monday 18 April 2011

Close All Browser QTP

‘ 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 comments:

Dheeraj Gambhir said...

Another method is:

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

TestEverything said...

Yes,This will also work.
http://rajivkumarnandvani.wordpress.com/2009/02/05/close-all-browser/

Dheeraj Gambhir said...

SystemUtil.CloseDescendentProcesses

CloseDescendentProcesses can be used to close any process launched by QTP. The code below illustrates the usage

'Launch explorer
SystemUtil.Run "iexplore.exe"

'Launch excel using COM
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True

'Close processes launched by QTP. This will close
'the internet explorer and Excel as well
SystemUtil.CloseDescendentProcesses

This method is best suited to be used during the end of a script to cleanup any process left open.

Post a Comment

Which one is right ?

Translate







Tweet