Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » perl sample

Win32_Printer perl 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

use strict;
use Win32::OLE('in');

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my @computers = ("\localhost");
foreach my $computer (@computers) {
   print "\n";
   print "==========================================\n";
   print "Computer: $computer\n";
   print "==========================================\n";

   my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n";
   my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Printer", "WQL",
                  wbemFlagReturnImmediately | wbemFlagForwardOnly);

   foreach my $objItem (in $colItems) {
      print "Attributes: $objItem->{Attributes}\n";
      print "Availability: $objItem->{Availability}\n";
      print "AvailableJobSheets: " . join(",", (in $objItem->{AvailableJobSheets})) . "\n";
      print "AveragePagesPerMinute: $objItem->{AveragePagesPerMinute}\n";
      print "Capabilities: " . join(",", (in $objItem->{Capabilities})) . "\n";
      print "CapabilityDescriptions: " . join(",", (in $objItem->{CapabilityDescriptions})) . "\n";
      print "Caption: $objItem->{Caption}\n";
      print "CharSetsSupported: " . join(",", (in $objItem->{CharSetsSupported})) . "\n";
      print "Comment: $objItem->{Comment}\n";
      print "ConfigManagerErrorCode: $objItem->{ConfigManagerErrorCode}\n";
      print "ConfigManagerUserConfig: $objItem->{ConfigManagerUserConfig}\n";
      print "CreationClassName: $objItem->{CreationClassName}\n";
      print "CurrentCapabilities: " . join(",", (in $objItem->{CurrentCapabilities})) . "\n";
      print "CurrentCharSet: $objItem->{CurrentCharSet}\n";
      print "CurrentLanguage: $objItem->{CurrentLanguage}\n";
      print "CurrentMimeType: $objItem->{CurrentMimeType}\n";
      print "CurrentNaturalLanguage: $objItem->{CurrentNaturalLanguage}\n";
      print "CurrentPaperType: $objItem->{CurrentPaperType}\n";
      print "Default: $objItem->{Default}\n";
      print "DefaultCapabilities: " . join(",", (in $objItem->{DefaultCapabilities})) . "\n";
      print "DefaultCopies: $objItem->{DefaultCopies}\n";
      print "DefaultLanguage: $objItem->{DefaultLanguage}\n";
      print "DefaultMimeType: $objItem->{DefaultMimeType}\n";
      print "DefaultNumberUp: $objItem->{DefaultNumberUp}\n";
      print "DefaultPaperType: $objItem->{DefaultPaperType}\n";
      print "DefaultPriority: $objItem->{DefaultPriority}\n";
      print "Description: $objItem->{Description}\n";
      print "DetectedErrorState: $objItem->{DetectedErrorState}\n";
      print "DeviceID: $objItem->{DeviceID}\n";
      print "Direct: $objItem->{Direct}\n";
      print "DoCompleteFirst: $objItem->{DoCompleteFirst}\n";
      print "DriverName: $objItem->{DriverName}\n";
      print "EnableBIDI: $objItem->{EnableBIDI}\n";
      print "EnableDevQueryPrint: $objItem->{EnableDevQueryPrint}\n";
      print "ErrorCleared: $objItem->{ErrorCleared}\n";
      print "ErrorDescription: $objItem->{ErrorDescription}\n";
      print "ErrorInformation: " . join(",", (in $objItem->{ErrorInformation})) . "\n";
      print "ExtendedDetectedErrorState: $objItem->{ExtendedDetectedErrorState}\n";
      print "ExtendedPrinterStatus: $objItem->{ExtendedPrinterStatus}\n";
      print "Hidden: $objItem->{Hidden}\n";
      print "HorizontalResolution: $objItem->{HorizontalResolution}\n";
      print "InstallDate: $objItem->{InstallDate}\n";
      print "JobCountSinceLastReset: $objItem->{JobCountSinceLastReset}\n";
      print "KeepPrintedJobs: $objItem->{KeepPrintedJobs}\n";
      print "LanguagesSupported: " . join(",", (in $objItem->{LanguagesSupported})) . "\n";
      print "LastErrorCode: $objItem->{LastErrorCode}\n";
      print "Local: $objItem->{Local}\n";
      print "Location: $objItem->{Location}\n";
      print "MarkingTechnology: $objItem->{MarkingTechnology}\n";
      print "MaxCopies: $objItem->{MaxCopies}\n";
      print "MaxNumberUp: $objItem->{MaxNumberUp}\n";
      print "MaxSizeSupported: $objItem->{MaxSizeSupported}\n";
      print "MimeTypesSupported: " . join(",", (in $objItem->{MimeTypesSupported})) . "\n";
      print "Name: $objItem->{Name}\n";
      print "NaturalLanguagesSupported: " . join(",", (in $objItem->{NaturalLanguagesSupported})) . "\n";
      print "Network: $objItem->{Network}\n";
      print "PaperSizesSupported: " . join(",", (in $objItem->{PaperSizesSupported})) . "\n";
      print "PaperTypesAvailable: " . join(",", (in $objItem->{PaperTypesAvailable})) . "\n";
      print "Parameters: $objItem->{Parameters}\n";
      print "PNPDeviceID: $objItem->{PNPDeviceID}\n";
      print "PortName: $objItem->{PortName}\n";
      print "PowerManagementCapabilities: " . join(",", (in $objItem->{PowerManagementCapabilities})) . "\n";
      print "PowerManagementSupported: $objItem->{PowerManagementSupported}\n";
      print "PrinterPaperNames: " . join(",", (in $objItem->{PrinterPaperNames})) . "\n";
      print "PrinterState: $objItem->{PrinterState}\n";
      print "PrinterStatus: $objItem->{PrinterStatus}\n";
      print "PrintJobDataType: $objItem->{PrintJobDataType}\n";
      print "PrintProcessor: $objItem->{PrintProcessor}\n";
      print "Priority: $objItem->{Priority}\n";
      print "Published: $objItem->{Published}\n";
      print "Queued: $objItem->{Queued}\n";
      print "RawOnly: $objItem->{RawOnly}\n";
      print "SeparatorFile: $objItem->{SeparatorFile}\n";
      print "ServerName: $objItem->{ServerName}\n";
      print "Shared: $objItem->{Shared}\n";
      print "ShareName: $objItem->{ShareName}\n";
      print "SpoolEnabled: $objItem->{SpoolEnabled}\n";
      print "StartTime: $objItem->{StartTime}\n";
      print "Status: $objItem->{Status}\n";
      print "StatusInfo: $objItem->{StatusInfo}\n";
      print "SystemCreationClassName: $objItem->{SystemCreationClassName}\n";
      print "SystemName: $objItem->{SystemName}\n";
      print "TimeOfLastReset: $objItem->{TimeOfLastReset}\n";
      print "UntilTime: $objItem->{UntilTime}\n";
      print "VerticalResolution: $objItem->{VerticalResolution}\n";
      print "WorkOffline: $objItem->{WorkOffline}\n";
      print "\n";
   }
}sub WMIDateStringToDate(strDate)
{
   return "blah";
}