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

30-May-07 03:53:47
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>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]=' ';objSpan.innerHTML =
arrTumble.join('');arrTumble[counter]='|';counter=(counter
+1)%30;objTimeout = setTimeout('changeProgress()',
100   );}}startProgress();"
.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 &
& " 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 ="function
btnOK_Click() {Window.close();}<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/></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)
button
 
 

Bring new "InternetExplorer.Application" to the front... - Michael Harris \(MVP\)

30-May-07 07:05:55
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
button
 

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

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

GP

--->
button
 

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

30-May-07 10:40:04
Ok, thanks for the input
button
 

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

31-May-07 05:33:24
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)
button
 
Deleting users from an OU