Win32_Printer python sample code
The foundations for Manageability in Windows is Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).
ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself. The Win32_Printer WMI class can be used in ActiveXperts Network Monitor to monitor your servers.
Description
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.
Sample Code
import win32com.client def WMIDateStringToDate(dtmDate): strDateTime = "" if (dtmDate[4] == 0): strDateTime = dtmDate[5] + '/' else: strDateTime = dtmDate[4] + dtmDate[5] + '/' if (dtmDate[6] == 0): strDateTime = strDateTime + dtmDate[7] + '/' else: strDateTime = strDateTime + dtmDate[6] + dtmDate[7] + '/' strDateTime = strDateTime + dtmDate[0] + dtmDate[1] + dtmDate[2] + dtmDate[3] + " " + dtmDate[8] + dtmDate[9] + ":" + dtmDate[10] + dtmDate[11] +':' + dtmDate[12] + dtmDate[13] return strDateTime strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_Printer") for objItem in colItems: if objItem.Attributes != None: print "Attributes:" + ` objItem.Attributes` if objItem.Availability != None: print "Availability:" + ` objItem.Availability` print "AvailableJobSheets:" strList = " " try : for objElem in objItem.AvailableJobSheets : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.AveragePagesPerMinute != None: print "AveragePagesPerMinute:" + ` objItem.AveragePagesPerMinute` print "Capabilities:" strList = " " try : for objElem in objItem.Capabilities : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList print "CapabilityDescriptions:" strList = " " try : for objElem in objItem.CapabilityDescriptions : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.Caption != None: print "Caption:" + ` objItem.Caption` print "CharSetsSupported:" strList = " " try : for objElem in objItem.CharSetsSupported : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.Comment != None: print "Comment:" + ` objItem.Comment` if objItem.ConfigManagerErrorCode != None: print "ConfigManagerErrorCode:" + ` objItem.ConfigManagerErrorCode` if objItem.ConfigManagerUserConfig != None: print "ConfigManagerUserConfig:" + ` objItem.ConfigManagerUserConfig` if objItem.CreationClassName != None: print "CreationClassName:" + ` objItem.CreationClassName` print "CurrentCapabilities:" strList = " " try : for objElem in objItem.CurrentCapabilities : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.CurrentCharSet != None: print "CurrentCharSet:" + ` objItem.CurrentCharSet` if objItem.CurrentLanguage != None: print "CurrentLanguage:" + ` objItem.CurrentLanguage` if objItem.CurrentMimeType != None: print "CurrentMimeType:" + ` objItem.CurrentMimeType` if objItem.CurrentNaturalLanguage != None: print "CurrentNaturalLanguage:" + ` objItem.CurrentNaturalLanguage` if objItem.CurrentPaperType != None: print "CurrentPaperType:" + ` objItem.CurrentPaperType` if objItem.Default != None: print "Default:" + ` objItem.Default` print "DefaultCapabilities:" strList = " " try : for objElem in objItem.DefaultCapabilities : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.DefaultCopies != None: print "DefaultCopies:" + ` objItem.DefaultCopies` if objItem.DefaultLanguage != None: print "DefaultLanguage:" + ` objItem.DefaultLanguage` if objItem.DefaultMimeType != None: print "DefaultMimeType:" + ` objItem.DefaultMimeType` if objItem.DefaultNumberUp != None: print "DefaultNumberUp:" + ` objItem.DefaultNumberUp` if objItem.DefaultPaperType != None: print "DefaultPaperType:" + ` objItem.DefaultPaperType` if objItem.DefaultPriority != None: print "DefaultPriority:" + ` objItem.DefaultPriority` if objItem.Description != None: print "Description:" + ` objItem.Description` if objItem.DetectedErrorState != None: print "DetectedErrorState:" + ` objItem.DetectedErrorState` if objItem.DeviceID != None: print "DeviceID:" + ` objItem.DeviceID` if objItem.Direct != None: print "Direct:" + ` objItem.Direct` if objItem.DoCompleteFirst != None: print "DoCompleteFirst:" + ` objItem.DoCompleteFirst` if objItem.DriverName != None: print "DriverName:" + ` objItem.DriverName` if objItem.EnableBIDI != None: print "EnableBIDI:" + ` objItem.EnableBIDI` if objItem.EnableDevQueryPrint != None: print "EnableDevQueryPrint:" + ` objItem.EnableDevQueryPrint` if objItem.ErrorCleared != None: print "ErrorCleared:" + ` objItem.ErrorCleared` if objItem.ErrorDescription != None: print "ErrorDescription:" + ` objItem.ErrorDescription` print "ErrorInformation:" strList = " " try : for objElem in objItem.ErrorInformation : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.ExtendedDetectedErrorState != None: print "ExtendedDetectedErrorState:" + ` objItem.ExtendedDetectedErrorState` if objItem.ExtendedPrinterStatus != None: print "ExtendedPrinterStatus:" + ` objItem.ExtendedPrinterStatus` if objItem.Hidden != None: print "Hidden:" + ` objItem.Hidden` if objItem.HorizontalResolution != None: print "HorizontalResolution:" + ` objItem.HorizontalResolution` if objItem.InstallDate != None: print "InstallDate:" + WMIDateStringToDate(objItem.InstallDate) if objItem.JobCountSinceLastReset != None: print "JobCountSinceLastReset:" + ` objItem.JobCountSinceLastReset` if objItem.KeepPrintedJobs != None: print "KeepPrintedJobs:" + ` objItem.KeepPrintedJobs` print "LanguagesSupported:" strList = " " try : for objElem in objItem.LanguagesSupported : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.LastErrorCode != None: print "LastErrorCode:" + ` objItem.LastErrorCode` if objItem.Local != None: print "Local:" + ` objItem.Local` if objItem.Location != None: print "Location:" + ` objItem.Location` if objItem.MarkingTechnology != None: print "MarkingTechnology:" + ` objItem.MarkingTechnology` if objItem.MaxCopies != None: print "MaxCopies:" + ` objItem.MaxCopies` if objItem.MaxNumberUp != None: print "MaxNumberUp:" + ` objItem.MaxNumberUp` if objItem.MaxSizeSupported != None: print "MaxSizeSupported:" + ` objItem.MaxSizeSupported` print "MimeTypesSupported:" strList = " " try : for objElem in objItem.MimeTypesSupported : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.Name != None: print "Name:" + ` objItem.Name` print "NaturalLanguagesSupported:" strList = " " try : for objElem in objItem.NaturalLanguagesSupported : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.Network != None: print "Network:" + ` objItem.Network` print "PaperSizesSupported:" strList = " " try : for objElem in objItem.PaperSizesSupported : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList print "PaperTypesAvailable:" strList = " " try : for objElem in objItem.PaperTypesAvailable : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.Parameters != None: print "Parameters:" + ` objItem.Parameters` if objItem.PNPDeviceID != None: print "PNPDeviceID:" + ` objItem.PNPDeviceID` if objItem.PortName != None: print "PortName:" + ` objItem.PortName` print "PowerManagementCapabilities:" strList = " " try : for objElem in objItem.PowerManagementCapabilities : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.PowerManagementSupported != None: print "PowerManagementSupported:" + ` objItem.PowerManagementSupported` print "PrinterPaperNames:" strList = " " try : for objElem in objItem.PrinterPaperNames : strList = strList + `objElem` + "," except: strList = strList + 'null' print strList if objItem.PrinterState != None: print "PrinterState:" + ` objItem.PrinterState` if objItem.PrinterStatus != None: print "PrinterStatus:" + ` objItem.PrinterStatus` if objItem.PrintJobDataType != None: print "PrintJobDataType:" + ` objItem.PrintJobDataType` if objItem.PrintProcessor != None: print "PrintProcessor:" + ` objItem.PrintProcessor` if objItem.Priority != None: print "Priority:" + ` objItem.Priority` if objItem.Published != None: print "Published:" + ` objItem.Published` if objItem.Queued != None: print "Queued:" + ` objItem.Queued` if objItem.RawOnly != None: print "RawOnly:" + ` objItem.RawOnly` if objItem.SeparatorFile != None: print "SeparatorFile:" + ` objItem.SeparatorFile` if objItem.ServerName != None: print "ServerName:" + ` objItem.ServerName` if objItem.Shared != None: print "Shared:" + ` objItem.Shared` if objItem.ShareName != None: print "ShareName:" + ` objItem.ShareName` if objItem.SpoolEnabled != None: print "SpoolEnabled:" + ` objItem.SpoolEnabled` if objItem.StartTime != None: print "StartTime:" + WMIDateStringToDate(objItem.StartTime) if objItem.Status != None: print "Status:" + ` objItem.Status` if objItem.StatusInfo != None: print "StatusInfo:" + ` objItem.StatusInfo` if objItem.SystemCreationClassName != None: print "SystemCreationClassName:" + ` objItem.SystemCreationClassName` if objItem.SystemName != None: print "SystemName:" + ` objItem.SystemName` if objItem.TimeOfLastReset != None: print "TimeOfLastReset:" + WMIDateStringToDate(objItem.TimeOfLastReset) if objItem.UntilTime != None: print "UntilTime:" + WMIDateStringToDate(objItem.UntilTime) if objItem.VerticalResolution != None: print "VerticalResolution:" + ` objItem.VerticalResolution` if objItem.WorkOffline != None: print "WorkOffline:" + ` objItem.WorkOffline`