Active Window

I have the following code in a .vbs file
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1

Do While (objExplorer.Busy)
Loop

Set objDocument = objExplorer.Document
objDocument.Open
objDocument.Writeln "<html><head><title>Service Status</title></head>"
objDocument.Writeln "<body bgcolor='white'>"
objDocument.Writeln "Retrieving service information. Please wait. <p>"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Service")
 
For Each objService in colServices
 objDocument.Writeln "*"
Next

objDocument.Writeln "<br>Service information retrieved."
objDocument.Writeln "</body></html>"
Wscript.Sleep 4000
objDocument.Close
objExplorer.Quit
when the code executes IE is not the active window
how can i make it the active window...the code is directly from MSDN
thanks
LVL 1
jduawaAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (50)

Computer101
EE Admin
0
 
ZylochCommented:
Hi

Have you tried this:


On Error Resume Next
AppActivate "about:blank - Microsoft Internet Explorer"
If Err.Number <> 0 Then
   MsgBox "MSIE not opened!"
End If


Regards,
Zyloch
0
 
jduawaAuthor Commented:
i just tried that and  got the message box...where in the code would it go...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ZylochCommented:
It depends on when you need IE to be active, possibly before the objExplorer.Quit, but I can't be sure since I haven't really ventured into this area a lot.
0
 
jduawaAuthor Commented:
it should be active as soon as it opens the IE window
0
 
ZylochCommented:
Then put it right after the Set objExplorer = CreateObject("InternetExplorer.Application")
0
 
jduawaAuthor Commented:
still doesnt work...
0
 
ZylochCommented:
Wait, currently, what part of the code isn't executing because IE doesn't get focus?
0
 
jduawaAuthor Commented:
the code runs fine but IE runs behind the other windows....
0
 
ZylochCommented:
Try putting it before the Set objDocument = objExplorer.Document
0
 
jduawaAuthor Commented:
i actually found this script online which does what i need....
i just need to place my code in it
' IEDisplay.vbs
' VBScript program to use Microsoft Internet Explorer to display a
' dynamic dialog box indicating program progress.
'
' ----------------------------------------------------------------------
' Copyright (c) 2002 Richard L. Mueller
' Hilltop Lab web site - http://www.rlmueller.net
' Version 1.0 - November 11, 2002
' Version 1.1 - February 19, 2003 - Standardize Hungarian notation.
' Program uses Internet Explorer to display a dialog box whose message
' changes to reflect progress in the program. The user can abort the
' program by closing the dialog box. The program requires Microsoft
' Internet Explorer on the client. The Wscript.Sleep command requires
' Windows Script Host (WSH) 5.1 or greater.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

Option Explicit

Dim objIE, objShell, k, strIETitle, blnFlag

' Set IE display box title. Dashes ("-") are to move the Microsoft title
' appended to the title we specify out of view.
' blnFlag is set to False when the user closes the IE display box.
strIETitle = "Test Program" & String(40, "-")
blnFlag = True

Set objShell = CreateObject("WScript.Shell")

' Initialize display box with initial message
InitIE "Program Initializing"

' Display progress with counter.
' Program can be aborted by closing the display box.
Wscript.Sleep 2000
For k = 0 To 10
  MsgIE "Iteration " & k & vbCrLf & "To abort, close this box"
  Wscript.Sleep 1000
  If blnFlag = False Then
    Wscript.Echo "Program Aborted after " & k & " iterations"
    Wscript.Quit
  End If
Next
MsgIE "Loop complete"

' Display final message
Wscript.Sleep 2000
MsgIE "Program Finished"

If blnFlag = False Then
  Wscript.Echo "Program Aborted after iterations complete"
  Wscript.Quit
End If

' Close display box
Wscript.Sleep 2000
MsgIE "IE_Quit"

' Clean Up.
Set objIE = Nothing
Set objShell = Nothing
Wscript.Echo "Done"

Sub MsgIE(strMsg)
' Subroutine to display message in IE box and detect when the
' box is closed by the program or the user.
  On Error Resume Next
  If strMsg = "IE_Quit" Then
    blnFlag = False
    objIE.Quit
  Else
    objIE.Document.Body.InnerText = strMsg
    If Err.Number <> 0 Then
      Err.Clear
      blnFlag = False
      Exit Sub
    End If
    objShell.AppActivate strIETitle
  End If
End Sub

Sub InitIE(strMsg)
' Subroutine to initialize the IE display box.
  Dim intWidth, intHeight, intWidthW, intHeightW
  Set objIE = CreateObject("InternetExplorer.Application")
  With objIE
    .ToolBar = False
    .StatusBar = False
    .Resizable = False
    .Navigate("about:blank")
    Do Until .readyState = 4
      Wscript.Sleep 100
    Loop
    With .document
      With .ParentWindow
        intWidth = .Screen.AvailWidth
        intHeight = .Screen.AvailHeight
        intWidthW = .Screen.AvailWidth * .40
        intHeightW = .Screen.AvailHeight * .05
        .resizeto intWidthW, intHeightW
        .moveto (intWidth - intWidthW)/2, (intHeight - intHeightW)/2
      End With
      .Write "<body> " & strMsg & " </body></html>"
      With .ParentWindow.document.body
        .style.backgroundcolor = "LightBlue"
        .scroll="no"
        .style.Font = "10pt 'Courier New'"
        .style.borderStyle = "outset"
        .style.borderWidth = "4px"
      End With
      .Title = strIETitle
      objIE.Visible = True
      Wscript.Sleep 100
      objShell.AppActivate strIETitle
    End With
  End With
End Sub
0
 
ZylochCommented:
NIce job, you should refund your points then.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.