** Example 1: ** ====== package require twapi set bIEFound 0 #-- Is IE already running? set app [ twapi::comobj Shell.Application ] set wnds [ $app Windows ] set index 0 set length [ $wnds Count ] while { $index < $length } { set itm [ $wnds Item $index ] set name [ $itm FullName ] set name [ string tolower $name ] if { [ string first "iexplore.exe" $name ] >= 0 } { set bIEFound 1 set ie $itm set szUrl [ $ie LocationURL ] set szUrl [ string tolower $szUrl] #-- This is sometimes troublesome, if IE already running while { [ $ie Busy ] } { puts -nonewline "." flush stdout after 250 } $ie Navigate "http://wiki.tcl.tk/_/search" break } incr index } if { $bIEFound } { #-- Yes; make it visible set w [ $ie HWND ] set wIE [ list $w HWND ] $ie Visible 1 #-- Force to foreground focus twapi::show_window $wIE -normal -activate twapi::set_focus $wIE } else { #-- No; start it set ie [ twapi::comobj InternetExplorer.Application ] $ie Visible 0 set szUrl "http://wiki.tcl.tk/_/search" $ie Navigate $szUrl $ie Visible 1 set w [ $ie HWND ] set wIE [ list $w HWND ] } while { [ $ie Busy ] } { puts -nonewline "." flush stdout after 250 } set doc [ $ie Document ] while { [ $doc readyState ] != "complete" } { after 250 } set body [ $doc body ] set inputs [ $body getElementsByTagName "input" ] set index 0 set length [ $inputs length ] while { $index < $length } { set input [ $inputs item $index ] set name [ $input name ] if { [ string compare $name "S" ] == 0 } { $input value "twapi" $input focus $input Send "{ENTER}" break } incr index } set buttons [ $body getElementsByTagName "input" ] set index 0 set length [ $buttons length ] while { $index < $length } { set button [ $buttons item $index ] set name [ $button name ] if { [ string compare $name "submit" ] == 0 } { $button focus after 250 $button click break } incr index } ====== Scenarios: 1. Run the script above with no IE instance running - '''success'''. 2. Start IE and leave on default home page, then run the script above - '''success'''. 3. Run the script above with no IE instance running, then run it again - '''no success'''. It stays in while loop under the comment #-- This is sometimes troublesome, if IE already running. Apparently an IE resource is in use.