Ericb2 Posted February 9, 2016 Posted February 9, 2016 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
Bowmore Posted February 9, 2016 Posted February 9, 2016 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
lewisg Posted February 10, 2016 Posted February 10, 2016 Script-o-matic (for AutoIT) could be your friend. Jon's AutoIT Script-o-matic
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now