Previous Page
Next Page

Monitoring Print Queues

To understand your print environment, it is necessary to examine the way the queues on the print servers are used. The MonitorPrintQueue.vbs script uses the Win32_PrintJob WMI class to obtain useful information about the load placed on your print servers. Because MonitorPrintQueue.vbs is based on previous scripts, you will look only at the Worker and Output information section of the script. You assign "Select * from Win32_PrintJob" to the wmiQuery variable in the Reference section. That is the main change required in that section.

MonitorPrintQueue.vbs

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem
Dim intTotalJobs
Dim intTotalPages
Dim intMaxPrintJob

strComputer = '.'
wmiNS = '\root\cimv2'
wmiQuery = 'Select * from win32_PrintJob'
Set objWMIService = GetObject('winmgmts:\\' _
  & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)

If colItems.count = 0 Then
  WScript.Echo('There are no print jobs at this time')
Else
  For Each objItem In colItems
    intTotalJobs = intTotalJobs + 1
    intTotalPages = intTotalPages + objItem.TotalPages
    If objItem.TotalPages > intMaxPrintJob Then
      intMaxPrintJob = objItem.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
End If

Worker and Output Information

To return meaningful information, you use the Count property of colItems just like you did in the previous script. If there are print jobs in the collection, iterate through them by using the For Each...Next construction. To get a count of the total number of print jobs in the queue, you use a counter called intTotalJobs, which gets incremented each time you loop through the collection of print jobs. For each print job in the collection, you get the TotalPages property and add it to the intTotalPages variable. By keeping a running total of pages, once you iterate through the collection, you will know the total pages left in the queue. To determine the largest print job in the queue, you use the variable called intMaxPrintJob and evaluate the size of each print job on the server. On each iteration through the collection of print jobs, we will list the print job size. Each time a larger print job is found, its value will be stored in intMaxPrintJob. At the end of the iteration, the largest print job will be stored in intMaxPrintJob, the total number of pages will be stored in the intTotalPages variable, and the total number of print jobs will be stored in the intTotalJobs variable.


Previous Page
Next Page