just_add_watir | Advanced recipes for Watir
22Jul/08Off

Q. How do I terminate a browser using a pid?

A. Get a window handle and close the pid using the Win32API ...
Example watir:

hWnd ||= Watir::IE::Process.process_id_from_hwnd @b.hwnd
pid=" " * 32
thread=Win32API.new("user32", "GetWindowThreadProcessId", 'IP', 'I').Call(hWnd,pid)
puts pid.unpack("L")[0]
right_to_terminate_process = 1
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').
call(right_to_terminate_process, 0, hWnd)
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'l').call(handle, 0)
Tagged as: Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.