Tuesday, April 19, 2011

QTP code to terminate all instances of Internet explorer using collections

'Code to close all Internet explorer browser process using QTP

Dim oWMIService, allIExplorer,iEItem
Dim strComputer

strcomputer="."

'Get the WMI object
Set oWMIService=GetObject("Winmgmts:\\"& strcomputer & "\root\cimv2")

'Get collection of processes for with name iexplore.exe
set allIExplorer=obj.execquery("Select * from win32_process where name='iexplore.exe'")
name
'Loop through each process and terminate it
For each iEItem in allIExplorer
iEItem.terminate
Next

Set allIExplorer= Nothing
Set oWMIService= Nothing

Click here for similar QTP scripts.

3 comments:

  1. This code is only working for QTP 11.0, IE7 and Windows XP environment. But if the same code will execute in Windos7, IE8 than error will occur.

    ReplyDelete
  2. If you have solution for Window 7 and IE8 than please send me on pardeepohri@gmail.com

    ReplyDelete
  3. set allIExplorer=obj.execquery("Select * from win32_process where name='iexplore.exe'")

    in above line replace 'obj' with 'oWMIService'

    ReplyDelete

Please leave your comment here...