<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to Close All Open Browsers Using QTP</title>
	<atom:link href="http://www.dbuggr.com/abhaybharti/close-open-browsers-qtp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dbuggr.com/abhaybharti/close-open-browsers-qtp/</link>
	<description>Share Knowledge &#38; Be Rewarded</description>
	<lastBuildDate>Fri, 03 Feb 2012 23:13:48 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Abhay</title>
		<link>http://www.dbuggr.com/abhaybharti/close-open-browsers-qtp/comment-page-1/#comment-468</link>
		<dc:creator>Abhay</dc:creator>
		<pubDate>Mon, 07 Dec 2009 07:04:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.dbuggr.com/abhaybharti/close-open-browsers-qtp/#comment-468</guid>
		<description>&lt;strong&gt;Method 1 -&lt;/strong&gt;

&lt;code&gt;&#039;Check the existence of a browser and close it
&#039;until no more browsers exist

While Browser(&quot;creationtime:=0&quot;).Exist(0)

    &#039;Close the browser
    Browser(&quot;creationtime:=0&quot;).Close

Wend&lt;/code&gt;

Limitation - The code does not allow to ignore any specific browser (like Quality Center)
Though there another way by which can enumerate all open browser and close them in QTP and below demonstrates the same
&lt;strong&gt;
Method 2 -&lt;/strong&gt;

&lt;code&gt;&#039;Create a description for browser

Set oBrowser = Description.Create
oBrowser(&quot;micclass&quot;).Value = &quot;Browser&quot;

Set oPage = Description.Create
oPage(&quot;micclass&quot;).Value = &quot;Page&quot;

&#039;Get all browsers
Set allBrowser = Desktop.ChildObjects(oBrowser)

Dim i, iCount

iCount = allBrowser.Count - 1

For i = 0 To iCount
    &#039;Get the page object from the browser
    Set oPg = allBrowser(i).ChildObjects(oPage)(0)

    &#039;Get the URL of the
    If InStr(oPg.GetROProperty(&quot;title&quot;), &quot;Quality Center&quot;, vbTextCompare) = 0 Then
        &#039;Close the browser
        allBrowser(i).Close
    End If
Next&lt;/code&gt;


&lt;strong&gt;Method 3 -&lt;/strong&gt;
Closing processes using WMI

&lt;code&gt;Another way to close a process is to use Window management instrumentation (WMI)
&#039;Name/IP of the computer
sComp = &quot;.&quot;

&#039;Get the WMI object
Set WMI = GetObject(&quot;winmgmts:\\&quot; &amp; sComp &amp; &quot;\root\cimv2&quot;)

&#039;Get collection of processes for with name iexplore.exe
Set allIE = WMI.ExecQuery(&quot;Select * from Win32_Process Where Name = &#039;iexplore.exe&#039;&quot;)

&#039;Loop through each process and terminate it
For Each IE in allIE
    IE.Terminate()
Next&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><strong>Method 1 -</strong></p>
<p><pre><code>&#039;Check the existence of a browser and close it
&#039;until no more browsers exist

While Browser(&quot;creationtime:=0&quot;).Exist(0)

&nbsp;&nbsp;&nbsp;&nbsp;&#039;Close the browser
&nbsp;&nbsp;&nbsp;&nbsp;Browser(&quot;creationtime:=0&quot;).Close

Wend</code></pre></p>
<p>Limitation &#8211; The code does not allow to ignore any specific browser (like Quality Center)<br />
Though there another way by which can enumerate all open browser and close them in QTP and below demonstrates the same<br />
<strong><br />
Method 2 -</strong></p>
<p><pre><code>&#039;Create a description for browser

Set oBrowser = Description.Create
oBrowser(&quot;micclass&quot;).Value = &quot;Browser&quot;

Set oPage = Description.Create
oPage(&quot;micclass&quot;).Value = &quot;Page&quot;

&#039;Get all browsers
Set allBrowser = Desktop.ChildObjects(oBrowser)

Dim i, iCount

iCount = allBrowser.Count - 1

For i = 0 To iCount
&nbsp;&nbsp;&nbsp;&nbsp;&#039;Get the page object from the browser
&nbsp;&nbsp;&nbsp;&nbsp;Set oPg = allBrowser(i).ChildObjects(oPage)(0)

&nbsp;&nbsp;&nbsp;&nbsp;&#039;Get the URL of the
&nbsp;&nbsp;&nbsp;&nbsp;If InStr(oPg.GetROProperty(&quot;title&quot;), &quot;Quality Center&quot;, vbTextCompare) = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;Close the browser
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allBrowser(i).Close
&nbsp;&nbsp;&nbsp;&nbsp;End If
Next</code></pre></p>
<p><strong>Method 3 -</strong><br />
Closing processes using WMI</p>
<p><pre><code>Another way to close a process is to use Window management instrumentation (WMI)
&#039;Name/IP of the computer
sComp = &quot;.&quot;

&#039;Get the WMI object
Set WMI = GetObject(&quot;winmgmts:\\&quot; &amp; sComp &amp; &quot;\root\cimv2&quot;)

&#039;Get collection of processes for with name iexplore.exe
Set allIE = WMI.ExecQuery(&quot;Select * from Win32_Process Where Name = &#039;iexplore.exe&#039;&quot;)

&#039;Loop through each process and terminate it
For Each IE in allIE
&nbsp;&nbsp;&nbsp;&nbsp;IE.Terminate()
Next</code></pre></p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
