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) |