Verifying the Status of the Print Service

Microsoft® Windows® 2000 Scripting Guide

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.

Scripting Steps

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:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_Service class.

    To limit data retrieval to the print service, use a Where clause that targets only the service with the name Spooler.

  4. For each service in the collection, echo the service name and the current service status.

Listing 13.6   Verifying the Status of the Print Service

1 2 3 4 5 6 7 8 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Service WHERE Name = 'Spooler'") For Each objService in colRunningServices     Wscript.Echo objService.DisplayName & ": " & objService.State Next

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 Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net