'========================================================================== ' ' ' NAME: ' ' AUTHOR: Ed Wilson , MS ' DATE : 10/28/2003 ' ' COMMENT: '1. Use of win32_Printer to monitor printers '2. Use of the WMI moniker '3. Use of for each next to iterate a collection '4. Use of select case to present useful status info '5. Use of the count property '========================================================================== Option Explicit 'On Error Resume Next dim strComputer dim wmiNS dim wmiQuery dim objWMIService dim colItems dim objItem strComputer = "." wmiNS = "\root\cimv2" wmiQuery = "Select * from win32_Printer" _ & " Where PrinterStatus = 1" _ & " or PrinterStatus = 2" _ & " or PrinterStatus = 7" Set objWMIService = GetObject("winmgmts:\\" _ & strComputer & wmiNS) Set colItems = objWMIService.ExecQuery(wmiQuery) If colItems.count = 0 Then WScript.Echo "All printers are fine" Else For Each objItem in colItems WScript.Echo "Name: " & objItem.Name WScript.Echo "Location: " & objItem.Location WScript.Echo "Printer Status: " & funEvalStatus(objItem.printerStatus) WScript.Echo "Server Name: " & objItem.ServerName WScript.Echo "Share Name: " & objItem.ShareName WScript.Echo Next End If Function funEvalStatus(intIN) Select Case intIN Case 1 funEvalStatus = "Other" Case 2 funEvalStatus = "Unknown" Case 3 funEvalStatus = "Idle" Case 4 funEvalStatus = "Printing" Case 5 funEvalStatus = "Warmup" Case 6 funEvalStatus = "Stopped Printing" Case 7 funEvalStatus = "Offline" End Select End Function