Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Running a script in a command window does not preclude you from using Internet Explorer as a way to track script progress; an Internet Explorer instance can be created and controlled from CScript in the same way it can be created and controlled from WScript.
At the same time, however, it is unusual for a command-line utility to generate a graphical progress indicator. Users might not recognize that the script running in the command window is tied to the progress indicator running in Internet Explorer. Because of this, you might want progress to be tracked in the same command window where the script is running.
Although you can track progress in a command window, there are at least two limitations:
Of course, you can use Wscript.Echo to periodically display progress messages in a command window. For example, you might have script output that looks similar to this:
C:\Scripts>cscript services.vbs Now completing Step 1 of 5. Now completing Step 2 of 5. Now completing Step 3 of 5. Now completing Step 4 of 5.
Another approach commonly used with command-line utilities is to display a series of dots (periods) as a script progresses:
C:\Scripts>cscript services.vbs Retrieving service information. This might take several minutes. ........................................................................
Each time the script performs a subtask, a new dot is written to the command window. However, this cannot be done by using Wscript.Echo. Each time you call Wscript.Echo, the value is written to a new line. Because of this, your progress indicator would look like this:
C:\Scripts>cscript services.vbs Retrieving service information. This might take several minutes. . . . .
To append text to the command window, you must instead use the Wscript.StdOut.Write method and write each new value to the standard output stream.
Important
Listing 17.28 contains a script that tracks script progress in a command window. 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.
A production script would probably do additional processing during this stage (for example, saving service information to a database). In this sample script, service information is retrieved but no additional action is taken.
Listing 17.28 Tracking Script Progress in a Command Window
|
|
Send us your feedback | « Previous | Next » |