Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Monitoring scripts typically check printer status, pause for a predetermined interval (for example, 10 minutes), and then check printer status again. This is done to minimize the processing power and network bandwidth required to monitor printers, and is usually based on an acceptable response time (as determined by your organization) for responding to printer problems. If your users are not severely impacted by a printer that might be out of commission for 10 minutes before support personnel are notified of the problem, then using a standard monitoring script that verifies printer status every 10 minutes is an acceptable approach.
However, for high-volume printers or for printers that print critical business documents (such as invoices), administrators might want immediate notification of any printer problem. For these printers, you can use a temporary event subscription that constantly monitors their status and immediately notifies you the moment one of these printers changes status (for example, a printer that was printing but is now jammed).
Listing 13.5 contains a script that monitors printer status by using a temporary event subscription. To carry out this task the script must perform the following steps:
Because the script monitors only changes to printers, include a Where clause that limits data retrieval to instance modifications involving the Win32_Printer class. The additional clause (within 30) causes the script to check every 30 seconds to see whether there has been a change in status. Therefore, status changes will not last longer than 30 seconds before being reported. In theory, a printer could stop and restart in less than 30 seconds. If that happened, the instance modification would go unreported.
To stop monitoring, terminate the process the script is running in.
These properties are retrieved from an event object known as the TargetInstance. Each time a printer is modified in some way, the script checks to see whether the current printer status differs from the previous printer status. If it does not, the script resumes looping. This check is performed by comparing the status property of the TargetInstance with the status property of the PreviousInstance, an event object representing the state of the printer prior to the last instance modification.
Comparing the previous state with the current state enables you to identify whether the modification involved a change in printer status (for example, going from Idle to Printing). If the previous and current states are the same, the modification did not involve printer status but instead reflects a change to some other property of the printer (for example, a change in the printer location).
Because printer status is returned as an integer, a pair of Select Case statements is used to convert the current status and the previous status to a more recognizable text string. For example, if the printer status is returned as 3, the word Idle will be displayed as part of the event notification message.
Listing 13.5 Monitoring Printer Status Using a Temporary Event Subscription
|
|
Send us your feedback | « Previous | Next » |