Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
In Windows 2000, printing is controlled by the Print Spooler service (usually called the print service). If this service is stopped, printing cannot take place. Because printing requires the Print Spooler service, any attempt to diagnose printer problems should include a check to ensure that this service is still running.
Checking the status of the Print Spooler service is especially important because the error messages presented to users when a printing problem occurs can be misleading. For example, if the Print Spooler service stops on the local computer, a user attempting to print a document receives this message:
Before you can perform printer-related tasks such as page setup or printing a document, you need to install a printer. Do you want to install a printer now?
If the user clicks Yes, this message is displayed:
Operation could not be completed.
Needless to say, this will leave the typical user helpless, and the problem might even be difficult for a support technician to initially diagnose and correct.
Likewise, if the Print Spooler service stops on a remote print server, a user attempting to print a document receives this cryptic message:
The RPC server is unavailable.
To programmatically check the status of the Print Spooler service, use the Win32_Service class.
Listing 13.6 contains a script that verifies the status of the print service. To carry out this task, the script must perform the following steps:
To limit data retrieval to the print service, use a Where clause that targets only the service with the name Spooler.
Listing 13.6 Verifying the Status of the Print Service
|
|
This script only returns the status of the Print Spooler service. In a production script, you might first check the status of the Print Spooler service and then attempt to restart the service if it has stopped. If the script is unable to restart the service, an administrative alert of some kind can then be issued. For more information about starting services by using WMI, see "Services" in this book.
Send us your feedback | « Previous | Next » |