Solved

Active Window

Posted on 2004-08-23
14
987 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:jduawa
  • 6
  • 5
14 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11873966
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
 
LVL 1

Author Comment

by:jduawa
ID: 11874056
i just tried that and  got the message box...where in the code would it go...
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11874373
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
 
LVL 1

Author Comment

by:jduawa
ID: 11874763
it should be active as soon as it opens the IE window
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11877533
Then put it right after the Set objExplorer = CreateObject("InternetExplorer.Application")
0
 
LVL 1

Author Comment

by:jduawa
ID: 11882102
still doesnt work...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 36

Expert Comment

by:Zyloch
ID: 11882481
Wait, currently, what part of the code isn't executing because IE doesn't get focus?
0
 
LVL 1

Author Comment

by:jduawa
ID: 11884879
the code runs fine but IE runs behind the other windows....
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11884892
Try putting it before the Set objDocument = objExplorer.Document
0
 
LVL 1

Author Comment

by:jduawa
ID: 11884904
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 11885058
NIce job, you should refund your points then.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12560987
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now