To Close all Internet Explorers

Before going to run your script needs to close all IEs,it helps you to work with QTP without any object /browser identification problems.

just have a look here,

Public function closeAllBrowsers()
Dim qtStartTime, ieStartTime, strComputer, objWMIService,ieProcessList,qtProcessList

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)

Set ieProcessList = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘iexplore.exe’”) to get all list  of IE  which are in process
Set qtpProcessList = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘qtpro.exe’”) ‘To get all list of qtp which are in process

For Each qtpProcess in qtpProcessList
dtStartTime = qtProcess.CreationDate    Date Time Month at the time of creation
qtStartTime = WMIDateStringToDate(dtmStartTime) ‘Returns qtp start time
Next

For Each ieProcess in ieProcessList
dtStartTime = ieProcess.CreationDate
ieStartTime = WMIDateStringToDate(dtmStartTime)  ‘Returns IE start time

If ieStartTime > qtStartTime Then    ‘If any IE browsers opened (process running) before QTP  process then it will close all
SystemUtil.CloseProcessById ieProcess.processid
End If
Next
End Function

‘To get Process time
Function WMIDateStringToDate(dtStart)
WMIDateStringToDate = CDate(Mid(dtmStart, 5, 2) & “/” & Mid(dtmStart, 7, 2) & “/” & Left(dtmStart, 4) & ” ” & Mid (dtmStart, 9, 2) & “:” & Mid(dtmStart, 11, 2) & “:” & Mid(dtmStart, 13, 2))
End Function

Advertisement
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.