MartyConnelly
martyconnelly at shaw.ca
Tue Feb 14 11:33:47 CST 2006
Here are some quick and dirty WMI scripts that will work on WinXP and Win2000 to check printers and spool queues. These should work with WinXP certified printers like high end HP's but not with printers cobbled together from recycled parts on the back streets of Naples. I believe WMI is looking at winspool.drv and not individual printer drivers. WMI is a work in progress just like IBM's HASP was 35 years ago. But HASP only had to work with a limited number of products and protocols Just to hook it to a pen plotter took a $1000 bisynch protocol converter. Just stick in your remote machine name into the code. It wont give you fine errors like out of toner. It also should tell you how long a wait there is in the print queue. There are many network monitor programs out there in the $500 range like http://www.activexperts.com/activmonitor/ Concievably knowing your jobname or id you could monitor the machine's print spool in a timer form and when the job id disappears from the queue sends you a SMS text message while you are sitting in Starbucks. 'http://www.activexperts.com/activmonitor/windowsmanagement/scripts/printing/printerport/#MonitorPrinterStatus2.htm Sub Test(Optional strComputerName As Variant) 'Checks the status for each printer on a computer, and issues an alert if any of these printers have stopped. Dim objWMIService As Object Dim colInstalledPrinters As Object Dim objPrinter As Variant Dim strComputer As String If IsMissing(strComputerName) Then strComputer = "." 'local machine default name Else strComputer = strComputerName End If Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer Where PrinterStatus = '1' " _ & "or PrinterStatus = '2'") If colInstalledPrinters.Count = 0 Then Debug.Print "All printers are functioning correctly." Else For Each objPrinter In colInstalledPrinters Debug.Print "Printer " & objPrinter.Name & " is not responding." Next End If End Sub Sub test2() 'Displays current status for all printers on a computer. Dim objWMIService As Object Dim colInstalledPrinters As Object Dim objPrinter As Variant Dim strComputer As String Dim strPrinterStatus As String strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter In colInstalledPrinters Debug.Print "Name: " & objPrinter.Name Debug.Print "Location: " & objPrinter.Location Select Case objPrinter.PrinterStatus Case 1 strPrinterStatus = "Other" Case 2 strPrinterStatus = "Unknown" Case 3 strPrinterStatus = "Idle" Case 4 strPrinterStatus = "Printing" Case 5 strPrinterStatus = "Warmup" End Select Debug.Print "Printer Status: " & strPrinterStatus Debug.Print "Server Name: " & objPrinter.ServerName Debug.Print "Share Name: " & objPrinter.ShareName Debug.Print Next End Sub Sub test3() 'Returns the job ID, user name, and total pages for each print job on a computer. Dim objWMIService As Object Dim colPrintJobs As Object Dim objPrintJob As Variant Dim strComputer As String Dim strPrinter As Variant strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPrintJobs = objWMIService.ExecQuery _ ("Select * from Win32_PrintJob") 'Page count may not be correct for multi-copy print of word document. Debug.Print "Print Queue, Job ID, Owner, Total Pages" For Each objPrintJob In colPrintJobs strPrinter = Split(objPrintJob.Name, ",", -1, 1) Debug.Print strPrinter(0) & ", " & _ objPrintJob.JobId & ", " & objPrintJob.Owner & ", " _ & objPrintJob.TotalPages Next End Sub Johncliviger at aol.com wrote: >Hi Marty > >Thank you for that comprehensive reply. I'm working my way through it. And >theres me thinking that a few lines of vb code in On-Print event will do the >job! Ah well who wants a simple life anyway? > >Thanks Marty > >regards > >john c >lancashire >uk > > -- Marty Connelly Victoria, B.C. Canada