Check windows printer before print

Is there a way to check if a “Windows Printer” is pressent with a javascript ot other script type before print ?

Printing PDF’s through the Workflow with the plugin " Print using a Windows driver"
Printernane is a variable.

Script should just return true or false.
If false then we have the option to send the print to a default printer, instead of creating an error in the workflow.

Thanks ind advance
Klaus

Hi,

Maybe using the SNMP condition plugin!

Hi,

Or use the error to send it to a default printer (error process)

There must be a script that can check for locally installed windows printers.
I don’t want to check if the “physical” printer is alive.
Just want to check i a named printer is installed under windows printers like a printer named “Administration”

I think Powershell is the script language to use.
Please google “check printer status Powershell” and you get lots of solutions.
e.g. https://stackoverflow.com/questions/45043125/printer-status-using-powershell
You can run Powershell scripts using “run external program” plug-in.

I have done it with Powershell script.
I was just hoping that it could have been done with a true/false javascript.

Klaus

The following JS code uses the WMI object to obtain printer information from Windows as an array of objects:

var printers = WMI_Printers();
for(var i=0;i<printers.length;i++){
  Watch.log(JSON.stringify(printers[i]),2)
}

function WMI_Printers (){
  try {
    var WMI = GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2');
  } catch (e) {
    throw "WMI not available - "+e;
  }
  return WMIQuery('SELECT * FROM Win32_Printer',true);

  function WMIQuery(query,isArr){
    var returnValue = isArr ? [] : {};
    var infos = WMI.ExecQuery(query);
    forEach( infos, function(colItem){
      var obj = {};
      forEach( colItem.Properties_, function(colP){
        obj[colP.Name] = colP.Value;
      });
      if(isArr) {
        returnValue.push(obj);
      } else {
        returnValue = obj;
      }
    });
    return returnValue;
  }

  function forEach(collection, func) {
    for (var o = new Enumerator(collection); !o.atEnd(); o.moveNext()) {
      func(o.item());
    }
  }
}

There’s a huge amount of information available through the WMI object, I have been planning on writing a blog article about it, but never seem to get around to it!