Previous Page
Next Page

One Step Further: Checking the Status of a Print Server

In this section, you will check the status of a print server, and if the server is not OK, you will cancel all print jobs on the box. This script is based on the FilterPrinterStatus.vbs script, so you use a starter file.

1.
Open \My Documents\Microsoft Press\VBScriptSBS\ch18\OneStepFurther\FilterPrinterStatus.vbs in Notepad or your favorite script editor. Save the script as Your NameCheckServerStatusCancelPrintJobs.vbs.

2.
Delete the entire subEvalstatus subroutine from the bottom of the script. This subroutine looks like the following:

Sub subEvalStatus
  Select Case objItem.PrinterStatus
    Case 1
      strStatus = "Other"
    Case 2
      strStatus = "Unknown"
    Case 3
      strStatus = "Idle"
    Case 4
      strStatus = "Printing"
    Case 5
      strStatus = "Warmup"
    Case 6
      strStatus = "Stopped Printing"
    Case 7
      strStatus = "Offline"
  End Select
End sub

3.
Locate the For Each...Next construction. Delete everything that is between the For Each and the Next. The For Each...Next statement is seen below. You will need to remove all the WScript.Echo commands and the subEvalStatus statement from the code below:

For Each objItem in colItems
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "Location: " & objItem.Location
  subEvalStatus
  WScript.Echo "Printer Status: " & strStatus
  WScript.Echo "Server Name: " & objItem.ServerName
  WScript.Echo "Share Name: " & objItem.ShareName
  WScript.Echo
Next

4.
Inside the For Each...Next construction, echo out the objItem.Name property with an appropriate label. It will look like the following:

WScript.Echo "Name: " & objItem.Name

5.
Under the WScript command, use the variable canStatus to hold the value contained in the objItem.CancelAllJobs property. The CancelAllJobs method has a return value that you want to capture with the canStatus variable. This line of code looks like the following:

canStatus = objItem.cancelAllJobs

6.
Use WScript.Echo to echo out the value of canStatus. The completed For Each...Next construction now looks like the following:

For Each objItem In colItems
  WScript.Echo "Name: " & objItem.Name
  canStatus = objItem.CancelAllJobs
WScript.Echo(canStatus)
Next

7.
Add the variable canStatus to the declarations section of the script.

8.
Save and run the script. If it does not perform as expected, compare it to \My Documents\Microsoft Press\VBScriptSBS\ch18\OneStepFurther\CheckServerStatusCancelPrintJobs.vbs.

Chapter 18 Quick Reference

To

Do This

Use WMI to find comprehensive information about printers

Use the WIN32_Printer class

Find information about print jobs on either a workstation or on a server

Use the WIN32_PrintJobs class

Retrieve the number of items in a collection returned by the ExecQuery method of the SWbemServices object

Use the Count property of the SWbemObjectSet object

Reduce the number of records returned by a WMI query

Use a Where clause with the query



Previous Page
Next Page