Solved

Active Window

Posted on 2004-08-23
14
985 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

11 Experts available now in Live!

Get 1:1 Help Now