Sign in to follow this  
Followers 0
Ericb2

Network printer status

3 posts in this topic

I found this code and it works well but I want to make a few tweaks, and since I am very new to this I was hoping I could ask for some education.  I understand enough to know that first few lines are what pull the printers, but I want to understand  how exactly that is going on.  In this case I want to specify a printer and not pull every one, can someone please explain. 
Thanks

$intPrinters = 1

$objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")

For $objItem In $colItems
    MsgBox(0,"Printer Info","Printers on " _
             & $objItem.name & ", Printer Number: " & $intPrinters & @LF & _
            "====================================" & @LF & _
            "Availability: " & $objItem.Availability & @LF & _
            "Description: " & $objItem.Description & @LF & _
            "Printer: " & $objItem.DeviceID & @LF & _
            "Driver Name: " & $objItem.DriverName & @LF & _
            "Port Name: " & $objItem.PortName & @LF & _
            "Printer State: " & $objItem.PrinterState & @LF & _
            "Printer Status: " & $objItem.PrinterStatus & @LF & _
            "PrintJobDataType: " & $objItem.PrintJobDataType & @LF & _
            "Print Processor: " & $objItem.PrintProcessor & @LF & _
            "Spool Enabled: " & $objItem.SpoolEnabled & @LF & _
            "Separator File: " & $objItem.SeparatorFile & @LF & _
            "Queued: " & $objItem.Queued & @LF & _
            "Status: " & $objItem.Status & @LF & _
            "StatusInfo: " & $objItem.StatusInfo & @LF & _
            "Published: " & $objItem.Published & @LF & _
            "Shared: " & $objItem.Shared & @LF & _
            "ShareName: " & $objItem.ShareName & @LF & _
            "Location: " & $objItem.Location & @LF & _
            "Priority: " & $objItem.Priority & @LF & _
            "Work Offline: " & $objItem.WorkOffline & @LF & _
            "Horizontal Res: " & $objItem.HorizontalResolution & @LF & _
            "Vertical Res: " & $objItem.VerticalResolution )
    $intPrinters = $intPrinters + 1
Next

 

Share this post


Link to post
Share on other sites



This is the line you need to change to restrict which printers are returned.

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")

  Example: Selects a specific printer by name

; Finds only printers named HP LaserJet 1020
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer where name = 'HP LaserJet 1020' ")

Example: Selects all printers with a similar name.

; Finds only printers that have LaserJet as part of theire name % is a wildcard that matches anything
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer where name like '%LaserJet%' ")

Any of the other fields can also be use in the same or similar way to specify which one are returned.  (some have numeric values rather than a string)


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0