MartyConnelly
martyconnelly at shaw.ca
Mon Feb 13 15:39:45 CST 2006
Lets say this maybe difficult but not impossible. The key thing is not all printer drivers play nice and may not give you the error codes you are hoping for. You cannot directly connect to the hardware and must use the printer driver for information. The drivers error's reporting back could "Unknown" or "Other" when the printer consoles display "Paper Jam" etc. You could look at the print queue and gather information there to see if job has finished. But this means constant polling of the printer or using event methods. But the print queue does not track finished jobs. Also your user app may not run with sufficient OS permissions. These guys at Merrion used to have a lot of info about VB using above methods but they have moved on to dotNet and the info is bit harder to get The info was moved to this Yahoo Group Look at printer status http://www.merrioncomputing.com/Programming/PrintStatus.htm Have a look at the sample files here and the archives of their message lists http://groups.yahoo.com/group/MerrionComputing/messages http://groups.yahoo.com/group/MerrionComputing/files/ Printer Queue Watch Docs http://groups.yahoo.com/group/MerrionComputing/files/PrinterQueueWatch%20Help/ You might get away with some of these WMI routines if your drivers are WMI compatible Sub lookupprinters() On Error Resume Next strComputer = "." Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIservice.ExecQuery("Select * from Win32_Printer", , 48) For Each objitem In colItems Debug.Print "Attributes: " & objitem.Attributes Debug.Print "Availability: " & objitem.Availability Debug.Print "AveragePagesPerMinute: " & objitem.AveragePagesPerMinute Debug.Print "Capabilities: " & CLng(objitem.Capabilities(0)) Debug.Print "CapabilityDescriptions: " & objitem.CapabilityDescriptions(0) Debug.Print "Caption: " & objitem.Caption Debug.Print "ConfigManagerErrorCode: " & objitem.ConfigManagerErrorCode Debug.Print "ConfigManagerUserConfig: " & objitem.ConfigManagerUserConfig Debug.Print "CreationClassName: " & objitem.CreationClassName Debug.Print "DefaultPriority: " & objitem.DefaultPriority Debug.Print "Description: " & objitem.Description Debug.Print "DetectedErrorState: " & objitem.DetectedErrorState Debug.Print "DeviceID: " & objitem.DeviceID Debug.Print "DriverName: " & objitem.DriverName Debug.Print "ErrorCleared: " & objitem.ErrorCleared Debug.Print "ErrorDescription: " & objitem.ErrorDescription Debug.Print "HorizontalResolution: " & objitem.HorizontalResolution ' Debug.Print "InstallDate: " & CDate(objitem.InstallDate) 'null check above Debug.Print "JobCountSinceLastReset: " & objitem.JobCountSinceLastReset Debug.Print "LanguagesSupported: " & objitem.LanguagesSupported Debug.Print "LastErrorCode: " & objitem.LastErrorCode Debug.Print "Location: " & objitem.Location Debug.Print "Name: " & objitem.Name Debug.Print "PaperSizesSupported: " & objitem.PaperSizesSupported(0) Debug.Print "PNPDeviceID: " & objitem.PNPDeviceID Debug.Print "PortName: " & objitem.PortName Debug.Print "PowerManagementCapabilities: " & objitem.PowerManagementCapabilities Debug.Print "PowerManagementSupported: " & objitem.PowerManagementSupported Debug.Print "PrinterPaperNames: " & objitem.PrinterPaperNames(0) Debug.Print "PrinterState: " & objitem.PrinterState Debug.Print "PrinterStatus: " & objitem.PrinterStatus Debug.Print "PrintJobDataType: " & objitem.PrintJobDataType Debug.Print "PrintProcessor: " & objitem.PrintProcessor Debug.Print "SeparatorFile: " & objitem.SeparatorFile Debug.Print "ServerName: " & objitem.ServerName Debug.Print "ShareName: " & objitem.ShareName Debug.Print "SpoolEnabled: " & objitem.SpoolEnabled ' Debug.Print "StartTime: " & CDate(objitem.StartTime) ' 'null check above Debug.Print "Status: " & objitem.Status Debug.Print "StatusInfo: " & objitem.StatusInfo Debug.Print "SystemCreationClassName: " & objitem.SystemCreationClassName Debug.Print "SystemName: " & objitem.SystemName 'Debug.Print "TimeOfLastReset: " & CDate(objitem.TimeOfLastReset) 'null check above Debug.Print "UntilTime: " & objitem.UntilTime Debug.Print "VerticalResolution: " & objitem.VerticalResolution Next Set colItems1 = objWMIservice.ExecQuery("Select * from Win32_Printer", , 48) For Each objitem In colItems1 Debug.Print "Attributes: " & objitem.Attributes Debug.Print "Attributes: " & objitem.Name Next End Sub Sub liststatus() strComputer = "." Set objWMIservice = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPrinters = objWMIservice. _ ExecNotificationQuery("Select * from __instancemodificationevent " _ & "within 30 where TargetInstance isa 'Win32_Printer'") I = 0 Do While I = 10 Set objprinter = colPrinters.NextEvent If objprinter.TargetInstance.PrinterStatus <> _ objprinter.PreviousInstance.PrinterStatus Then Select Case objprinter.TargetInstance.PrinterStatus Case 1 strCurrentState = "Other" Case 2 strCurrentState = "Unknown" Case 3 strCurrentState = "Idle" Case 4 strCurrentState = "Printing" Case 5 strCurrentState = "Warming Up" End Select Select Case objprinter.PreviousInstance.PrinterStatus Case 1 strPreviousState = "Other" Case 2 strPreviousState = "Unknown" Case 3 strPreviousState = "Idle" Case 4 strPreviousState = "Printing" Case 5 strPreviousState = "Warming Up" End Select Debug.Print objprinter.TargetInstance.Name _ & " is " & strCurrentState _ & ". The printer previously was " & strPreviousState & "." End If I = I + 1 Loop End Sub Sub testprt() Dim objWMIservice As Object Dim colInstalledPrinters As Object Dim objprinter As Variant Dim strComputer As String 'printer codes 'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp 'Set objWMIservice = _ 'GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") strComputer = "." Set objWMIservice = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") ' Grab the list of printers in the colInstallPrinters list. Set colInstalledPrinters = objWMIservice.ExecQuery("Select * from Win32_Printer ") ' Run through the printer collection. For Each objprinter In colInstalledPrinters Debug.Print objprinter.Name If objprinter.Status = "Error" Then Debug.Print "Detected Printer error" & objprinter.Name Debug.Print "DetectedErrorState - " & objprinter.DetectedErrorState Debug.Print "ExtendedDetectedErrorState - " & _ objprinter.ExtendedDetectedErrorState Debug.Print "PrinterStatus - " & objprinter.PrinterStatus Debug.Print "ExtendedPrinterStatus - " & _ objprinter.ExtendedPrinterStatus End If Next Set colInstalledPrinters = Nothing Set objWMIservice = Nothing End Sub Johncliviger at aol.com wrote: >Hi all >I'm printing documents from AXP using cmd_Onclick to drive a report and all >is fine. That is until the printer elsewhere in the building cocks it up and >we need a re-print. How can I know sat at my AXP workstation that the document >has fails to print? > >TIA > >john c > > -- Marty Connelly Victoria, B.C. Canada