'========================================================================== ' ' ' NAME: ' ' AUTHOR: Ed Wilson , MS ' DATE : 10/28/2003 ' ' COMMENT: '1. Use of win32_PrintJob to monitor printers '2. Use of the WMI moniker '3. Use of for each next to iterate a collection '========================================================================== 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