Reporting Print Queue Statistics

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Monitoring the number of jobs in a print queue can provide a rough estimate of the printer workload. However, the number of jobs in a print queue can be misleading. For example, a single document of 250 pages ties up a printer longer than 100 single-page documents. Likewise, a pair of 10-page documents filled with intricate graphics might take longer to print than that same 250-page, all-text print job.

Unless your users tend to print the same type of document over and over (for example, an all-text document no more than a few pages long), you might need to use a more precise metric when monitoring print queues. In a situation such as that, you can use the Win32_PrintJob class to tally not only the number of jobs in the queue but also the number of pages scheduled to be printed or the total number of bytes still in the queue.

Neither the total number of pages to be printed nor the total number of bytes in the queue is provided as a Win32_PrintJob property. Instead, you must retrieve the number of pages and number of bytes for each print job and then add these values to determine the total number of pages and total number of bytes to be printed. This provides more comprehensive data than merely reporting the number of jobs in a queue. For example, the script can also calculate such values as the largest print job in the queue and the average number of pages per print job.

Scripting Steps

Listing 13.7 contains a script that reports cumulative print queue statistics for a specific print server. 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. For each print job in the collection, do the following:
    1. Increment the total number of print jobs (intTotalJobs) by 1. Print jobs are incremented in this fashion to illustrate how calculations can be performed within a script. However, you can also use the WMI Count property to report the number of print jobs in the collection.
    2. Add the number of pages in the print job to the total number of pages for all the active print jobs (intTotalPages).
    3. If the total number of pages in the print job is greater than the value intMaxPrintJob, replace the value of intMaxPrintJob with the number of pages in the current print job. The variable intMaxPrintJob will thus store the size of the largest print job in the queue (based on page count).
  5. Echo the values for total print jobs, total number of pages for the print jobs in the print queues, and the largest print job in the queue.

Listing 13.7   Reporting Print Queue Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPrintJobs =  objWMIService.ExecQuery _     ("SELECT * FROM Win32_PrintJob") For Each objPrintJob in colPrintJobs     intTotalJobs = intTotalJobs + 1     intTotalPages = intTotalPages + objPrintJob.TotalPages     If objPrintJob.TotalPages > intMaxPrintJob Then         intMaxPrintJob = objPrintJob.TotalPages     End If Next Wscript.Echo "Total print jobs in queue: " & intTotalJobs Wscript.Echo "Total pages in queue: " & intTotalPages Wscript.Echo "Largest print job in queue: " & intMaxPrintJob

Note

  • The TotalPages property does not always reflect the number of pages to be printed. Most software applications (including the Microsoft® Office applications) correctly report the number of pages to be printed. However, some applications do not. For example, Notepad always reports a document as being a single page in length, regardless of the actual number of printed pages that will result from printing that document. If your organization uses software that does not correctly report total pages, you might want to measure the size of the print jobs instead.

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