Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
If you feel that a script needs a progress indicator, it is recommended that you use a graphical progress indicator; after all, if visual cues are important, your progress indicator should be visually compelling. Perhaps the easiest way to add a graphical progress indicator to your scripts is to use Internet Explorer.
By the way, this is true even if the script runs in a command window under CScript; Internet Explorer can be instantiated and used as a progress indicator even if the script is running from the command line.
One way to indicate progress by using Internet Explorer is to display a message in the browser. In some cases, you might want to display a single message ("Please wait .") and then have the message disappear when the script is finished. Alternatively, you might want to periodically change the message to reflect whatever the script is doing. For example, if you have a script that stopped a service, waited two minutes, and then restarted the service, you might display these messages in the browser:
Regardless of the number or the type of messages you choose to display, you can display custom messages within Internet Explorer by configuring the InnerHTML property of the document body. This replaces the entire document body with the specified text. For example, this code clears the document and displays the message, "Service retrieval in progress.":
objExplorer.Document.Body.InnerHTML =
"Service retrieval in progress.
"
You can also use standard HTML tags to include formatting when setting the InnerHTML property. For example, this code uses the < B> tag to display the message in bold:
objExplorer.Document.Body.InnerHTML =
"<B>Service information retrieved.</B>
"
There are two important points to keep in mind when using Internet Explorer as a progress indicator:
To prevent this, use On Error Resume Next statement within the script. Anytime you attempt to manipulate Internet Explorer, check the error number. If the error number is anything other than 0, that means a problem occurred, and it is likely that Internet Explorer is no longer available. In that case, you must decide whether you want your script to terminate itself, continue without a progress indicator, or generate a new instance of Internet Explorer.
For information about a way to overcome these problems, see "Stopping a Script When Internet Explorer Is Closed" in this chapter.
Listing 17.25 contains a script that tracks script progress by using Internet Explorer. To carry out this task, the script must perform the following steps:
This query returns a collection consisting of all the services installed on the computer.
Listing 17.25 Tracking Script Progress by Using Internet Explorer
|
|
Send us your feedback | « Previous | Next » |