search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
.NET Framework GroupsView
Deployment Server
.NET Distributed_Apps
.NET
.NET ADO.NET
.NET ASP.NET
.NET ASP.NET Security
.NET ASP.NET Webcontrols
.NET ASP.NET Web Services
.NET Clr
.NET Compact Framework
.NET Drawing
.NET Interop
.NET Micro Porting
.NET Performance
.NET Web Services
.NET Windows Forms
.NET Windows Forms Controls
.NET General
.NET Csharp
.NET Visual Basic
.NET Vc
.NET Security
.NET Xml
Scripting Jscript
Scripting Visual Basicscript
Scripting Wsh
Smartphone Developer
Visual Basic Com
Visual Basic Controls
Visual Basic Crystal
Visual Basic Database Ado
Visual Basic Syntax
Visual Basic Vista Compatibility
Visual Basic Winapi
Vc Atl
Vc Debugger
Vc Language
Vc Mfc
Vc Stl
Visio Developer Visual Basica
Vsnet Debugging
Windows Powershell
Windowsce Embedded Vc
Xml
Xsl

Group SummariesView
.NET Framework
Access
BizTalk
Certifications
CRM
DDK
Exchange Server
FoxPro
French
French .NET
Games
German
German .NET
Graphic Design
IIS
Internet
ISA Server
Italian
Italian .NET
Maps
MCIS
Miscellaneous
Mobile Application Development
Money
MSN
Networking
Office
Ops Mgr
Publisher
Security
SharePoint
Small Business
Spanish
Spanish .NET
SQL Server
Systems Management Server
Transaction Server
Virtual PC / Virtual Server
Visual Studio
Win32
Windows 2000
Windows 2003 Server
Windows 7
Windows Live
Windows Media
Windows Update
Windows Vista
Windows XP
 

View All Microsoft Scripting Visual Basicscript Posts  Ask A New Question 

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

Wednesday, May 30, 2007 3:53 PM

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

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

Wednesday, May 30, 2007 7:05 PM

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
reply

W2K is/was infected with this malady also. I couldn't find a solution either. - Grand_Poobah

Wednesday, May 30, 2007 10:06 PM

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

GP

--->
reply

Ok, thanks for the input - hzgt9b

Wednesday, May 30, 2007 10:40 PM

Ok, thanks for the input
reply

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

Thursday, May 31, 2007 5:33 PM

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

Previous Microsoft Scripting Visual Basicscript conversation.