Win32_Printer - WMI sample in JScript

The foundations for Manageability in Windows 7/2008/Vista/XP/2000 and Millennium Edition/'98 are 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.

On this site, you can find many WMI samples.


Win32_Printer

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.

Example(s)

var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;

var arrComputers = new Array("\localhost");
for (i = 0; i < arrComputers.length; i++) {
   WScript.Echo();
   WScript.Echo("==========================================");
   WScript.Echo("Computer: " + arrComputers[i]);
   WScript.Echo("==========================================");

   var objWMIService = GetObject("winmgmts:\\\\" + arrComputers[i] + "\\root\\CIMV2");
   var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL",
                                          wbemFlagReturnImmediately | wbemFlagForwardOnly);

   var enumItems = new Enumerator(colItems);
   for (; !enumItems.atEnd(); enumItems.moveNext()) {
      var objItem = enumItems.item();

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

function WMIDateStringToDate(dtmDate)
{
   if (dtmDate == null)
   {
      return "null date";
   }
   var strDateTime;
   if (dtmDate.substr(4, 1) == 0)
   {
      strDateTime = dtmDate.substr(5, 1) + "/";
   }
   else
   {
      strDateTime = dtmDate.substr(4, 2) + "/";
   }
   if (dtmDate.substr(6, 1) == 0)
   {
      strDateTime = strDateTime + dtmDate.substr(7, 1) + "/";
   }
   else
   {
      strDateTime = strDateTime + dtmDate.substr(6, 2) + "/";
   }
   strDateTime = strDateTime + dtmDate.substr(0, 4) + " " +
   dtmDate.substr(8, 2) + ":" +
   dtmDate.substr(10, 2) + ":" +
   dtmDate.substr(12, 2);
   return(strDateTime);
}