Monitoring Print Job Status

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Monitoring individual print jobs allows you to retrieve detailed information about each print job on a print server. In turn, this information allows you to:

  • Verify that documents are moving through the print queue at the expected rate.
  • Identify unusually large documents that might monopolize the printer.
  • Identify users who print an excessive number of documents.
  • Assist users with printing problems.

    For example, a user might call the Help desk complaining that a document has not been printed. By examining the print job status, a technician might notice that the document has been paused or that it has a low priority compared with other documents in the queue. In the latter case, this means that the document will not be printed until all the higher-priority jobs have completed.

You can use the Win32_PrintJob class to retrieve detailed information about every print job on a print server.

Scripting Steps

Listing 13.8 contains a script that monitors print job status. 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_PrintJob class.

    This query returns a collection consisting of all the print jobs on the computer.

  4. Echo the column headers Print Queue, Job ID, Owner, and Total Pages.
  5. For each print job in the collection, echo the name of the printer where the job is queued, the job ID number, the person who submitted the print job, and the total number of pages in the print job.

    The Name property is a combination of the name of the printer where the job is queued and the ID number assigned to the print job. For example, a print job assigned ID number 522 on the printer ColorPrinter would have the following name:

    ColorPrinter, 522

    The VBScript Split function is used to split the printer name and the print job ID into an array. In this script, the Split function uses the following parameters:

    • objPrintJob.Name Print job name (for example, ColorPrinter, 522). This is the value being split into the array.
    • , Delimiter used to separate fields in the string.
    • 1 Indicates that all substrings of the array should be returned.
    • 1 Indicates that a text comparison should be performed. To perform a binary comparison, enter 0 as the parameter.

    When the Split function is called, the print job name will be split into an array with two elements: Element 0 will contain the name of the printer, and element 1 will contain the job ID. To reference the printer name, simply specify element 0 in the array. For example:

    Wscript.Echo strPrinter(0)

Listing 13.8   Monitoring Print Job Status

1 2 3 4 5 6 7 8 9 10 11 12 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPrintJobs =  objWMIService.ExecQuery _     ("SELECT * FROM Win32_PrintJob") Wscript.Echo "Print Queue, Job ID, Owner, Total Pages" For Each objPrintJob in colPrintJobs     strPrinter = Split(objPrintJob.Name,",",-1,1)     Wscript.Echo strPrinter(0) & ", " & _         objPrintJob.JobID & ", " &  objPrintJob.Owner & ", " _             & objPrintJob.TotalPages Next

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