<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>just_add_watir &#124; Advanced recipes for Watir &#187; Win32API</title>
	<atom:link href="http://justaddwatir.com/tag/win32api/feed/" rel="self" type="application/rss+xml" />
	<link>http://justaddwatir.com</link>
	<description>Advanced recipes for Watir</description>
	<lastBuildDate>Wed, 21 Oct 2009 02:44:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Q. How do I terminate a browser using a pid?</title>
		<link>http://justaddwatir.com/2008/q-how-do-i-terminate-a-browser-using-a-pid/</link>
		<comments>http://justaddwatir.com/2008/q-how-do-i-terminate-a-browser-using-a-pid/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 09:47:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[Win32API]]></category>

		<guid isPermaLink="false">http://justaddwatir.com/watir/?p=11</guid>
		<description><![CDATA[A. Get a window handle and close the pid using the Win32API ...
Example watir:

hWnd &#124;&#124;= Watir::IE::Process.process_id_from_hwnd @b.hwnd
pid=&#34; &#34; * 32
thread=Win32API.new&#40;&#34;user32&#34;, &#34;GetWindowThreadProcessId&#34;, 'IP', 'I'&#41;.Call&#40;hWnd,pid&#41;
puts pid.unpack&#40;&#34;L&#34;&#41;&#91;0&#93;
right_to_terminate_process = 1
handle = Win32API.new&#40;'kernel32.dll', 'OpenProcess', 'lil', 'l'&#41;.
call&#40;right_to_terminate_process, 0, hWnd&#41;
Win32API.new&#40;'kernel32.dll', 'TerminateProcess', 'll', 'l'&#41;.call&#40;handle, 0&#41;

]]></description>
			<content:encoded><![CDATA[<p><strong>A. Get a window handle and close the pid using the Win32API ...</strong><br />
Example watir:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">hWnd <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#6666ff; font-weight:bold;">Watir::IE::Process</span>.<span style="color:#9900CC;">process_id_from_hwnd</span> <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">hwnd</span>
pid=<span style="color:#996600;">&quot; &quot;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">32</span>
thread=Win32API.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;user32&quot;</span>, <span style="color:#996600;">&quot;GetWindowThreadProcessId&quot;</span>, <span style="color:#996600;">'IP'</span>, <span style="color:#996600;">'I'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">Call</span><span style="color:#006600; font-weight:bold;">&#40;</span>hWnd,pid<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> pid.<span style="color:#9900CC;">unpack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;L&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
right_to_terminate_process = <span style="color:#006666;">1</span>
handle = Win32API.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'kernel32.dll'</span>, <span style="color:#996600;">'OpenProcess'</span>, <span style="color:#996600;">'lil'</span>, <span style="color:#996600;">'l'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.
<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>right_to_terminate_process, <span style="color:#006666;">0</span>, hWnd<span style="color:#006600; font-weight:bold;">&#41;</span>
Win32API.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'kernel32.dll'</span>, <span style="color:#996600;">'TerminateProcess'</span>, <span style="color:#996600;">'ll'</span>, <span style="color:#996600;">'l'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>handle, <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justaddwatir.com/2008/q-how-do-i-terminate-a-browser-using-a-pid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
