Mitsules, Mark
Mark.Mitsules at ngc.com
Wed Oct 8 13:58:47 CDT 2003
I've messed with this in the past...if only I had administrator privileges on those remote print servers:( Mark -----Original Message----- From: MartyConnelly [mailto:martyconnelly at shaw.ca] Sent: Wednesday, October 08, 2003 2:40 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Re: When is a report actually printed If anyone wants to play around with interogating the Print Spooler and Queue Here is some starter code to examine it through WMI otherwise you have to use winSpool.dll WMI needs an install for Win9x and works remotely in Win2000 WinXP Option Compare Database Option Explicit 'Private Enum PrinterStatus ' PrinterIdle = 3 ' PrinterPrinting = 4 ' PrinterWarmingUp = 5 ' ' For more states see WMI docs. 'End Enum Sub LookthruWinSpooler() Dim strComputer As String Dim objWMIService As Object Dim colItems As Object Dim objItem As Object 'The Win32_PrintJob WMI class represents a print job generated 'by a Windows application. Any unit of work generated 'by the print command of an application running on a 'Windows system is a descendent (or member) of this class. 'Documentation of WMI classes: ' set reference to WMICntl 1.0 class library wbemcntl.dll 'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi /wmi_classes.asp 'http://www.activxperts.com/activmonitor/windowsmanagement/wmisamples/ On Error Resume Next strComputer = "." 'local computer Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_PrintJob", , 48) For Each objItem In colItems Debug.Print "Caption: " & objItem.Caption Debug.Print "DataType: " & objItem.DataType Debug.Print "Description: " & objItem.Description Debug.Print "Document: " & objItem.Document Debug.Print "DriverName: " & objItem.DriverName Debug.Print "ElapsedTime: " & objItem.ElapsedTime Debug.Print "HostPrintQueue: " & objItem.HostPrintQueue Debug.Print "InstallDate: " & objItem.InstallDate Debug.Print "JobId: " & objItem.JobId Debug.Print "JobStatus: " & objItem.JobStatus Debug.Print "Name: " & objItem.Name Debug.Print "Notify: " & objItem.Notify Debug.Print "Owner: " & objItem.Owner Debug.Print "PagesPrinted: " & objItem.PagesPrinted Debug.Print "Parameters: " & objItem.Parameters Debug.Print "PrintProcessor: " & objItem.PrintProcessor Debug.Print "Priority: " & objItem.Priority Debug.Print "Size: " & objItem.Size Debug.Print "StartTime: " & WMIDateStringToDate(objItem.StartTime) Debug.Print "Status: " & objItem.Status Debug.Print "StatusMask: " & objItem.StatusMask Debug.Print "TimeSubmitted: " & WMIDateStringToDate(objItem.TimeSubmitted) Debug.Print "TotalPages: " & objItem.TotalPages Debug.Print "UntilTime: " & objItem.UntilTime Next End Sub Function WMIDateStringToDate(dtmInstallDate) As String WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ & " " & Mid(dtmInstallDate, 9, 2) & ":" & _ Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2)) End Function Sub Win32_Printer() Dim strComputer As String Dim objWMIService As Object Dim colItems As Object Dim objItem As Object 'The Win32_Printer WMI class represents a device connected 'to a Windows computer system that can reproduce a 'visual image on paper or other medium. 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: " & objItem.Capabilities Debug.Print "CapabilityDescriptions: " & objItem.CapabilityDescriptions 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: " & objItem.InstallDate 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 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 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: " & objItem.StartTime Debug.Print "Status: " & objItem.Status Debug.Print "StatusInfo: " & objItem.StatusInfo Debug.Print "SystemCreationClassName: " & objItem.SystemCreationClassName Debug.Print "SystemName: " & objItem.SystemName Debug.Print "TimeOfLastReset: " & objItem.TimeOfLastReset Debug.Print "UntilTime: " & objItem.UntilTime Debug.Print "VerticalResolution: " & objItem.VerticalResolution Next End Sub Sub PrintQueueStats() Dim strComputer As String Dim objWMIService As Object Dim colPrintJobs As Object Dim objPrintJob As Object Dim intTotalJobs As Long Dim intTotalPages As Long Dim intMaxPrintJob As Long strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPrintJobs = objWMIService.ExecQuery _ ("SELECT * FROM Win32_PrintJob") For Each objPrintJob In colPrintJobs intTotalJobs = intTotalJobs + 1 intTotalPages = intTotalPages + objPrintJob.TotalPages If objPrintJob.TotalPages > intMaxPrintJob Then intMaxPrintJob = objPrintJob.TotalPages End If Next Debug.Print "Total print jobs in queue: " & intTotalJobs Debug.Print "Total pages in queue: " & intTotalPages Debug.Print "Largest print job pages in queue: " & intMaxPrintJob End Sub _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com