Tracking Dynamic Script Progress by Using Internet Explorer

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The script shown in Listing 17.26 displays a message when the script starts and then displays a second message when the script ends. To create a more dynamic progress bar, you might want to do something to indicate the intermediate steps taken by the script. This can be as simple as displaying an asterisk (*) inside the browser window each time a service is retrieved and acted upon.

To create a dynamic progress indicator, you can use the WriteLn method to write information to the browser each time the script takes a particular action. As a result, you end up with a progress indicator similar to the one shown in Figure 17.4. Each time a service is retrieved and acted upon, another asterisk is added to the browser window.

Figure 17.4   Tracking Dynamic Script Progress by Using Internet Explorer

Tracking Dynamic Script Progress by Using Internet Explorer

Tip

  • By using different fonts, you can create a progress indicator that uses solid bars or dots rather than asterisks. For example, the letter "n" in the Wingdings font looks like this: ν.

Scripting Steps

Listing 17.26 contains a script that tracks script progress dynamically by using Internet Explorer. To carry out this task, the script must perform the following steps:

  1. Create an instance of Internet Explorer.
  2. Open a blank Web page by navigating to "about:blank".
  3. Configure the user interface settings, and then show Internet Explorer by setting the Visible property to True.
  4. Create a reference to the Internet Explorer Document object, and then use the Open method to make a connection to the Document object. This allows your script to use commands such as WriteLn to write information to the browser window.
  5. Use the WriteLn method to create a title for the page, set the background color (bgcolor) to white, and create the message "Retrieving service information. Please wait." In addition to the message text, the HTML paragraph tag (<p>) is included. This ensures that the "progress bar" will be written on a separate line.
  6. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  7. Use the ExecQuery method to query the Win32_Service class.

    This query returns a collection consisting of all the services installed on the computer.

  8. For each service in the collection, use the WriteLn method to write an asterisk (*) in the browser window.
  9. Use the WriteLn method to write the message "Service information retrieved" to the browser window.
  10. Pause for 4 seconds (4,000 milliseconds). This pause is inserted simply to give the user a chance to see the message that service information has been retrieved.
  11. Close the Document object, and use the Quit method to dismiss Internet Explorer.

Listing 17.26   Tracking Dynamic Script Progress by Using Internet Explorer

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 
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 

Changing the Mouse Pointer

If you are using Internet Explorer as a progress indicator, you might want to change the mouse pointer to an hourglass; this will help emphasize the fact that an operation is in progress. The mouse pointer can be configured by setting the cursor style to one of the values shown in Table 17.11.

Table 17.11   MousePointer Values

ValueDescription
CrosshairSimple crosshair.
DefaultPlatform-dependent default cursor; usually an arrow.
HandHand with the first finger pointing up, as when the user moves the pointer over a link.
HelpArrow with question mark, indicating that help is available.
WaitHourglass or watch, indicating that the program is busy and the user must wait.

To change the mouse pointer, create a reference to the Internet Explorer Document object, and then set the cursor style to the appropriate value. For example, to display an hourglass while the script runs, use this code:

Set objDocument = objIE.Document objDocument.body.style.cursor = "wait" 

To reset the cursor later in the script, use this code:

objDocument.body.style.cursor = "default" 

Tracking Script Progress by Using an Animated .GIF

Because it is often difficult to report absolute script progress (for example, to note that a script is 37 percent complete), an alternative approach is to display a pseudo progress indicator that simply informs the user that an operation is in progress. For example, in Figure 17.5 an instance of Internet Explorer is used to note that a script operation is in progress. Instead of tracking the percentage of the operation that is complete, however, the dialog box merely displays a ticking clock and the message, "Please wait while service information is retrieved. This might take several minutes to complete."

Figure 17.5   Tracking Script Progress by Using an Animated .GIF

Tracking Script Progress by Using an Animated .GIF

To use this type of progress indicator, start by creating an HTML file that includes both an animated GIF (for example, a ticking clock or a moving hourglass) and any other message you want the user to see. In your script, you create an instance of Internet Explorer and then use the Navigate method to open the HTML file. When the script completes, you then use the Quit method to close Internet Explorer.

Scripting Steps

Listing 17.27 contains a script that tracks script progress by displaying a pseudo progress indicator. This progress indicator is simply a Web page that includes an animated .GIF and a message asking the user to please wait. (The assumption is that you have already created this Web page.) To carry out this task, the script must perform the following steps:

  1. Create an instance of Internet Explorer.
  2. Open the HTML page by navigating to "file://c:\scripts\progress.htm".
  3. Configure the user interface settings, and then show Internet Explorer by setting the Visible property to True.
  4. Create a reference to the Internet Explorer Document object.
  5. Set the cursor style to wait.
  6. Pause for 5 seconds (5,000 milliseconds). This is done simply to keep the browser window open long enough for you to see the progress indicator.
  7. Use the Quit method to dismiss Internet Explorer.

Listing 17.27   Using an Animated .GIF as a Progress Indicator

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
Set objIE = CreateObject("InternetExplorer.Application") objIE.navigate "file://c:\scripts\progress.htm" objIE.left=200 objIE.top=200 objIE.height=175 objIE.width=450 objIE.menubar=0 objIE.toolbar=0 objIE.addressbar=0 objIE.statusbar=0 objIE.visible=1 Do While (objIE.Busy)     Wscript.Sleep 200 Loop Set objDocument = objIE.Document objDocument.body.style.cursor = "wait" Wscript.Sleep 5000 objIE.Quit

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net