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