From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Programmatically Purge All Print Jobs on Local Printers Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 Overview

 This example uses the .NET API to search for local and default printers, and purges the queues of all printers. 

 

Description

This example shows how to programmatically purge the print jobs of all printers on your local machine. It also attempts to purge the print queue of your default printer. In some cases, this will be included on the local printer list, but sometimes it is a networked printer. If you do not have sufficient priviledges, an error will be thrown when attempting to purge the queue. Typically, you only have priviledges to purge wueus on your local machine, assuming you have administrative priviledges.

 

Play with this, and comment with your thoughts. This uses the .NET API to the System.Printing namespace and can be expanded to retrieve all active jobs, pause printing, cancel specific jobs on specific printers, or moving jobs to other printers.

 

Requirements 

  • LabVIEW 2012 (or compatible)
  • .NET framework 3.0 or later

 

Steps to Implement or Execute Code

  1. Run the VI
  2. The VI will search for all local printers and the default printer
  3. It will try to purge all printer queues and throw an error message if it doesn't succeed

 

 

 Additional Information or References

 On newer versions of the .NET API it might be necessary to change the "GetEnumerator" invoke node to "GetEnumerator()"

 

Front Panel of the VI

front panel.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

Block Diagram of the VI

block diagram.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

---

Peter Flores
Applications Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
B4S3M
Member
Member
on

can you upload it for Labview 8.5

kapella98
Member
Member
on

I am using an example called "Programmatically Purge All Print Jobs on Local Printers" from PFlores. In this VI there is a property node called PrinterQueue, and is set to retrieve all printers names availables on my PC. The names are all found successfully everytime. I tried to add another item on the same property node called IsOffline, to find what printers are offline and online. This function is always returning False values regardless of printers being off or on.  Do you know if I need to do something else?

Thanks for the big help.

Regards,

pflores
NI Employee (retired)
on

This seemed to work for me: http://screencast.com/t/YKZ5EQ8N4CO

I remember this API being very strange to work with, if that doesn't help, may have to read up in the MSDN docs, good luck!

System.Printing namespace

---

Peter Flores
Applications Engineer
kapella98
Member
Member
on

Ok thank you for your response. I tried your example but I couldn't make it work. I' m going to follow your advise about reading MSDN doc about System.Printing namespace.

Regards.

Date: Mon, 4 Apr 2011 22:01:48 -0500

From: web.community@ni.com

To: kapella98@hotmail.com

Subject: Re: - Programmatically Purge All Print Jobs on Local Printers

Community

Programmatically Purge All Print Jobs on Local Printers

new comment by pflores View all comments on this document

This seemed to work for me: http://screencast.com/t/YKZ5EQ8N4CO

I remember this API being very strange to work with, if that doesn't help, may have to read up in the MSDN docs, good luck!

System.Printing namespace

Reply to this email to respond to pflores's comment.

pflores
NI Employee (retired)
on

Sorry

Let us know what you find!

---

Peter Flores
Applications Engineer
Vincent_Carpentier
Member
Member
on
Thanks Peter for the example code. I do run into a Access-Denied error when I try to purge the pending document on my printing. My end-user will not logged in as an administrator so I need to make it work that way. I tried changing the DesiredAccess parameter (AdministrateServer and AdministratePrinter) but it did not work... This is running in LabVIEW 2013 on Windows 10.... Anybody had similar issue or has any ideas? I'll try running LabVIEW as an administrator to see if this fix it. Thanks, Vincent
Vincent Carpentier, Ing./Eng.
CLA, CPI
Neosoft Technologies
www.neosoft.ca
DQMH Trusted Advisor
Vincent_Carpentier
Member
Member
on
I tried by running LabVIEW in admin and still had the same error: System.Printing.PrintQueue.Purge, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. Inner Exception: System.Printing.PrintQueueException: An exception occurred while the queue was purged. Win32 error: Access is denied.) Possible reason(s): LabVIEW: A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation. System.Printing.PrintQueueException in Purge All Print Jobs.vi I'll continue my search
Vincent Carpentier, Ing./Eng.
CLA, CPI
Neosoft Technologies
www.neosoft.ca
DQMH Trusted Advisor