Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bringing IE to the foreground

128 views
Skip to first unread message

Csaba2000

unread,
Feb 21, 2005, 3:11:03 PM2/21/05
to
A standard way of bringing IE to the foreground upon creation is something
like:

Set oIE=CreateObject("InternetExplorer.Application")
oIE.visible=true
oIE.Navigate2("about:blank")
Do Until oIE.ReadyState = 4 : Wscript.Sleep 100 : Loop
CreateObject("WScript.Shell").AppActivate "about:blank"
oIE.Document.title = "New title"

As the .vbs script exits, IE is on top with: New Title - Microsoft Internet
Explorer
But is it guaranteed that the instance of IE just created is that one that
will be
snagged with AppActivate, if there are more "about:blank" titled IEs lying
around? The docs at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthappactivate.asp
say it's arbitrary (thought it's worked every time on my IE6 / Win XP Pro
SP2 system).


Contrast this with an approach where we give an (almost surely) unique
title to the new instance of IE to guarantee activation:

Set oIE=CreateObject("InternetExplorer.Application")
oIE.visible=true
oIE.Navigate2("about:blank")
Do Until oIE.ReadyState = 4 : Wscript.Sleep 50 : Loop
Randomize: myRand = Rnd()
oIE.Document.title = myRand 'a unique title
Wscript.Sleep 100 'necessary delay?
CreateObject("WScript.Shell").AppActivate myRand & " - M"
oIE.Document.title = "My new title"


Unfortunately, this vbscript is disturbing because of that Wscript.Sleep 100
If I make it too short (50 on my system) then not only will the new instance
not make it to the foreground, but it will signal it wants attention by
flashing
for about 3 seconds in XP's status bar at the bottom of the screen. I
checked
and busy/ReadyState are not helping out here. Also, the document's title is
changed right away so I can't check.

Is there some reliable check I can make to be sure that IE is prepared to
respond to AppActivate

Thanks,
Csaba Gabor from Vienna


0 new messages