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

Bring new "InternetExplorer.Application" to the front...

10,972 views
Skip to first unread message

hzgt9b

unread,
May 30, 2007, 3:53:47 PM5/30/07
to
When I open a new "Internet.Application", I am not able to
consistently "bring it the top" of the windows stack.
I've seen several threads on this topic and have implemented their
recommendations with varying success...

My particular problem is that IE does not (ever) open and comes to the
top when this script autoruns in Vista, and only sometimes opens and
comes to the top in XP.

Any input on on how to get this to work would be appreciated. (FYI,
I'm not concerned about keeping it on top... I just need to pop it up
one time)...

PS - I also have a javascript function that I'd like to call after
writing to the HTML document but I don't know how to kick the
javascript funcation off from vbscript -- any ideas here (see code
below)

CODE FOLLOWS:

Option Explicit
Dim objIE, objFSO, objFile, objTargetFile, objWin, strFileName,
strTargetFileName, strArrFiles(), bCopyNeeded, tBegin, tEnd, tDiff,
strMsg
Const STR_TARGET = "myTargetPath"
Redim Preserve strArrFiles(0)
strArrFiles(UBound(strArrFiles)) = "File1"
Redim Preserve strArrFiles(UBound(strArrFiles) + 1)
strArrFiles(UBound(strArrFiles)) = "File2"
Redim Preserve strArrFiles(UBound(strArrFiles) + 1)
strArrFiles(UBound(strArrFiles)) = "FileN"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(STR_TARGET) Then 'Do nothing
Else
objFSO.CreateFolder(STR_TARGET)
End if

Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate2 "about:blank"
.TheaterMode = True 'Being browser to the top...
.Toolbar = False
.Menubar = False
.Statusbar = False
.AddressBar = False
.Resizable = False
Do While (.Busy)
Wscript.Sleep 50
Loop
.Document.Body.style.cursor = "wait"
.Document.Body.InnerHTML="<div style='text-align:center'><div
id=text style='position:relative;top:35%;z-index:100;font-
family:Tahoma;font-size:14pt;font-weight:bold;text-
align:center;'>Please wait...<br/><br/><br/><span id='meter'></span></
div></div><script type='text/javascript'>var arrTumble = new
Array('|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|');var
objTimeout;var counter=0;function startProgress() {objTimeout =
setTimeout('changeProgress()', 0);}function changeProgress() {var
objSpan = document.getElementById('meter');if (objSpan)
{arrTumble[counter]='&nbsp;';objSpan.innerHTML =
arrTumble.join('');arrTumble[counter]='|';counter=(counter
+1)%30;objTimeout = setTimeout('changeProgress()',
100 );}}startProgress();</script>"
.Visible = True
' .Document.execScript("startProgress();") 'HERES MY PS QUESTION -
how do I kick off the startProgress() or changeProgress() javascript
functions written to the InnerHTML above?
tBegin = Time
For Each strFileName in strArrFiles
strTargetFileName = Right(strFileName, Len(strFileName)-
(InstrRev(strFileName, "\")))
Set objFile = objFSO.getFile(strFileName)
'wscript.echo "strFileName=" & strFileName & vbTab & "(" &
Cstr(objFile.Size) & " bytes)"
If objFSO.FileExists(STR_TARGET & strTargetFileName) Then
Set objTargetFile = objFSO.getFile(STR_TARGET & strTargetFileName)
'wscript.echo "strTargetFileName=" & strTargetFileName & vbTab &
"(" & Cstr(objTargetFile(" & STR_TARGET & strTargetFileName & ").Size)
& " bytes)"
if objFile.Size = objTargetFile.Size Then 'Do Nothing
'wscript.echo "objFile(" & strFileName & ").Size=" & objFile.Size
& vbnewline & "objTargetFile=" & objTargetFile.Size
Else
'wscript.echo "delete file + " & vbnewline & objFSO.CopyFile " &
strFileName & ", " & STR_TARGET & strTargetFileName
objFSO.DeleteFile STR_TARGET & strTargetFileName, true
objFSO.CopyFile strFileName, STR_TARGET & strTargetFileName
End If
Else
'wscript.echo "objFSO.CopyFile " & strFileName & ", " & STR_TARGET
& strTargetFileName
objFSO.CopyFile strFileName, STR_TARGET & strTargetFileName
End If
Next
tEnd = Time
tDiff = DateDiff("s", tBegin, tEnd)
If tDiff >= 60 Then
strMsg = (tDiff \ 60) & " minute"
if (tDiff \ 60) <> 1 Then
strMsg = strMsg & "s"
End If
tDiff = tDiff Mod 60
strMsg = strMsg & " and " & tDiff & " second"
If tDiff <> 1 Then
strMsg = strMsg & "s"
End If
Else
strMsg = tDiff & " second"
if tDiff <> 1 Then
strMsg = strMsg & "s"
End If
End If
.Document.Body.style.cursor = "default"
.Document.Body.InnerHTML ="<script type='text/javascript'>function
btnOK_Click() {Window.close();}</script><div
style='position:relative;top:42%;text-align:center;'><span style='font-
family:Tahoma;font-size:14pt;font-weight:bold;'>Install Complete! (" &
strMsg & ")<br/><br/></span><br/><br/><br/><br/><br/><span style='font-
family:Tahoma;font-size:12pt;font-weight:bold;'>Click OK to continue</
span><br/><input id='btnOK' type='button' value=' OK '></div>"
.Document.All.btnOk.onclick = getRef("btnOK_Click")
End With
While Not (objIE Is Nothing)
WScript.sleep 100
WEnd

Sub btnOK_Click
objIE.Quit
Set objIE = Nothing
End Sub

WScript.Quit(1)

Michael Harris (MVP)

unread,
May 30, 2007, 7:05:55 PM5/30/07
to
hzgt9b wrote:
> When I open a new "Internet.Application", I am not able to
> consistently "bring it the top" of the windows stack.
> I've seen several threads on this topic and have implemented their
> recommendations with varying success...
>
> My particular problem is that IE does not (ever) open and comes to the
> top when this script autoruns in Vista, and only sometimes opens and
> comes to the top in XP.
>
> Any input on on how to get this to work would be appreciated. (FYI,
> I'm not concerned about keeping it on top... I just need to pop it up
> one time)...


I'd call this an exercise in futility...

In XP and higher (maybe even W2K), Windows enforces some rules to prevent
newly launched windows from stealing the focus from the active window of
another application. This has been the subject of many threads over the
years with no consistent solution.


--
Michael Harris
Microsoft.MVP.Scripting


Grand_Poobah

unread,
May 30, 2007, 10:06:37 PM5/30/07
to
W2K is/was infected with this malady also. I couldn't find a solution
either. Sometimes it would work, sometimes it wouldn't.

GP

--->

hzgt9b

unread,
May 30, 2007, 10:40:04 PM5/30/07
to
Ok, thanks for the input

mr_unreliable

unread,
May 31, 2007, 5:33:24 PM5/31/07
to
hzgt9b wrote:
> When I open a new "Internet.Application", I am not able to
> consistently "bring it the top" of the windows stack.

Yes, microsoft has made it harder-and-harder to get a window
on top. Seems that it became annoying with every application
trying to push its way to the front. And, microsoft's own
programmers were some of the worst offenders.

That old trick of calling the "SetWindowPos" api with the
HWND_TOPMOST flag, only works for a while anyway, until the
next app trys to push its way to the front.

Here's a trick you might try. Enumerate the open windows,
keeping track of their "window state", and then minimize
all of them, leaving the app you want showing (all-by-itself)
on the screen. That's not exactly "in front", but then if
all the other windows are minimized, then it's all you see.
When you are finished, restore all the windows to their
previous window state.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Dan Bernhardt

unread,
Nov 3, 2010, 11:52:00 AM11/3/10
to
I know this is a very old thread, but a colleague of mine was still looking for answers to this question earlier today. Though I doubt it will help the OP now, perhaps it will help those still seeking the answer in the future.

Set objShell = WScript.CreateObject("WScript.Shell")
Set objIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
'Navigate and set settings
objIE.Visible = 1
objShell.AppActivate objIE


>> On Wednesday, May 30, 2007 7:05 PM Michael Harris \(MVP\) wrote:

>> hzgt9b wrote:
>>
>>
>> I'd call this an exercise in futility...
>>
>> In XP and higher (maybe even W2K), Windows enforces some rules to prevent
>> newly launched windows from stealing the focus from the active window of
>> another application. This has been the subject of many threads over the
>> years with no consistent solution.
>>
>>

>> --
>> Michael Harris
>> Microsoft.MVP.Scripting


>>> On Wednesday, May 30, 2007 10:06 PM Grand_Poobah wrote:

>>> W2K is/was infected with this malady also. I could not find a solution
>>> either. Sometimes it would work, sometimes it would not.
>>>
>>> GP
>>>
>>> --->


>>>> On Wednesday, May 30, 2007 10:40 PM hzgt9b wrote:

>>>> Ok, thanks for the input


>>>>> On Thursday, May 31, 2007 5:33 PM mr_unreliable wrote:

>>>>> hzgt9b wrote:
>>>>>
>>>>> Yes, microsoft has made it harder-and-harder to get a window
>>>>> on top. Seems that it became annoying with every application
>>>>> trying to push its way to the front. And, microsoft's own
>>>>> programmers were some of the worst offenders.
>>>>>
>>>>> That old trick of calling the "SetWindowPos" api with the
>>>>> HWND_TOPMOST flag, only works for a while anyway, until the
>>>>> next app trys to push its way to the front.
>>>>>
>>>>> Here's a trick you might try. Enumerate the open windows,
>>>>> keeping track of their "window state", and then minimize
>>>>> all of them, leaving the app you want showing (all-by-itself)
>>>>> on the screen. That's not exactly "in front", but then if
>>>>> all the other windows are minimized, then it's all you see.
>>>>> When you are finished, restore all the windows to their
>>>>> previous window state.
>>>>>
>>>>> cheers, jw
>>>>> ____________________________________________________________
>>>>>
>>>>> You got questions? WE GOT ANSWERS!!! ..(but,
>>>>> no guarantee the answers will be applicable to the questions)


>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>> Flat file Database with LINQ and ASP.NET jQuery Page Methods
>>>>> http://www.eggheadcafe.com/tutorials/aspnet/c8c43191-c3a3-4c61-801a-2433a701f4f6/flat-file-database-with-linq-and-aspnet-jquery-page-methods.aspx

Tom Lavedas

unread,
Nov 3, 2010, 1:56:51 PM11/3/10
to
On Nov 3, 11:52 am, Dan Bernhardt <danl...@yahoo.com> wrote:
> I know this is a very old thread, but a colleague of mine was still looking for answers to this question earlier today.  Though I doubt it will help the OP now, perhaps it will help those still seeking the answer in the future.
>
> Set objShell = WScript.CreateObject("WScript.Shell")
> Set objIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
> 'Navigate and set settings
> objIE.Visible = 1
> objShell.AppActivate objIE
>

Interesting approach, except that navigating before using the
AppActivate this way will almost certainly fail because the Name
property (default for IE.APP) you are using is not likely to match the
page's title in that case. Rather the activation needs to come before
the navigation, or the AppActivate needs to use the document's
title ...

Set objShell = CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
'Navigate and set settings
objIE.navigate "http://someplace.com/"
do : wsh.sleep 50 : loop until objIE.ReadyState = 4
objIE.Visible = 1
wsh.echo cstr(objShell.AppActivate(objIE.document.title))
_____________________
Tom Lavedas

xt_an...@live.be

unread,
Nov 28, 2010, 6:12:18 AM11/28/10
to

____________________________________________________

I can only say one thing,
The code given by Dan Bernhardt works perfectly,
but the code given by Tom lavedas, does not.
Thank you very much Dan Bernhardt, for this perfect solution.

Message has been deleted

Arsha...@ssdkolkata.com

unread,
Sep 12, 2013, 12:56:15 AM9/12/13
to
Thanks Dan Bernhardt.. it really helped me after trying whole day. :)

Mayayana

unread,
Sep 12, 2013, 8:56:05 AM9/12/13
to
<Arsha...@ssdkolkata.com> wrote in message
news:d40ed7f8-5545-4cd4...@googlegroups.com...
On Sunday, November 28, 2010

> Thanks Dan Bernhardt.. it really helped me after trying whole day. :)

It looks to me like you've been working on it for
almost 3 years. ....Please stop using Google Groups,
get a real newsreader, and learn how Usenet works.


0 new messages