Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Although many system administration scripts run in a command window, the command window is not always suitable for displaying process performance data. Within a command window, there are few options for formatting data: you are limited to a single nonproportional font, with each character the same size and color. In addition, data within the command window cannot be cleared by using a script. Neither Windows Script Host (WSH) nor VBScript provides methods for clearing the screen; although you can call the command-line utility cls from within a script, instead of the current command window being cleared a second command window opens, and the cls command is carried out there.
The inability to clear a command window has important implications for scripts that monitor process status or process performance. You cannot display the current process status, wait a few minutes, and then erase that data and replace it with updated status information. Instead, each time you retrieve process information, the new data is appended to the end of the existing data. While this large collection of data might be useful for viewing process performance over time, it is far less useful if you simply want to view the current state of each process running on a computer.
As an alternative to displaying process performance in a command window, you can use a hypertext application (HTA) that allows you to display process information on a Web page. Displaying process data in an HTA offers the following advantages:
An HTA is a Web page that has the file name extension .HTA. HTAs are useful for script writers because they can use Automation objects that have not been marked as safe for scripting. This allows you to use WMI within a Web page.
For more information about HTAs, see "Creating Enterprise Scripts" in this book.
Listing 14.7 contains the HTML tags and VBScript code required to create an HTA that displays process performance information on a Web page. Type this information into a text editor, and then save it with the .HTA file name extension.
To carry out the task of displaying process performance information on a Web page, the HTA must perform the following steps:
This constant is used to format the working set value for each process.
Code in the window_onLoad subroutine automatically runs whenever the window is loaded (either through initial startup or by clicking the browser Refresh button).
The setInterval method requires three parameters:
The setInterval method provides functionality similar to Wscript.Sleep: It allows you to pause the script for a specified amount of time and then resume processing. This method must be used instead of Wscript.Sleep because Windows Script Host (WSH) methods cannot be called from Internet Explorer.
To do this, the GetInfo subroutine must first delete the current version of the table (if one exists), create the table header, retrieve the process information, and then display the process information in the table.
Deleting the current table has the effect of wiping the page clean, allowing the latest process information to be displayed.
The loop works backward from the last row in the table (Rows.Length 1) to the first row in the table (row 0). If there are three rows in the table, row 2 is deleted first, then row 1, and then row 0.
To do this, the script must:
The FormatNumber function is used to insert comma delimiters in the working set values. By using this function, numbers are displayed with thousands separators, such as 3,456,789 rather than 3456789. The FormatNumber function requires the following parameters:
This tag is used to represent the actual body of the table.
Listing 14.7 Displaying Process Performance on a Web Page
|
|
The finished HTA appears similar to Figure 14.2. Every 10 seconds, the display is replaced with updated process information.
Figure 14.2 Process Performance Data Displayed on a Web Page
Process Performance Data Displayed on a Web Page
Send us your feedback | « Previous | Next » |