Showing posts with label Cancel All print queue. Show all posts
Showing posts with label Cancel All print queue. Show all posts

Tuesday, July 28, 2009

Printing Stuff: Clear/Purge All printing queue in a selected printer

Hi,

Lately, I was asked to create a utility to monitor a printer at specific time everyday. This utility will hopefully Clear/Purge All printing jobs waiting in the printer queue. After googling around I found this link which seems to be useful at first but some minor tweaking I think is lacking. The command, however, will Clear/Purge All printing jobs in the printer queue but not selectively. What I mean, is that, you have no way to select a specific printer in which this operation will execute. In short, it didn't meet the requirements I needed.

For this reason, I created some sort of utility using batch file(.bat) that will enable the user to Cancel All printing activities in a specific printer. I've been googling around in search for a solution for this kind of problem but unfortunately it is not yet available. So, I think it is better to post this answer for the benefit of others also.

So, here it is. This utility will use the "net print" command from MS-DOS. Just issue this command in DOS prompt to get the hang of it...hehehe
1. Click Start->run, then type, cmd, press Enter
2. Type net print /?
It will give you some sort of idea of what will be needed to accomplish the task at hand.

It also needs the IP address of the machine in which this utility will be run. So, issue this command also and take note the IP address: Ipconfig


Open your Printers and Faxes list in Control Panel and make sure printer name must not contain white-space(" ").

Create a new file(.bat), save it anywhere you like then open it, paste the code below.

@echo off
TITLE Purge Print Jobs

::Use the IP address we take note above
set localIP=\\xxx.xxx.xxx
::Add printer name below. White-space (" ") is not allowed in the printer name
set targetPrinter.1=Printer1
set targetPrinter.2=Printer2
set targetPrinter.3=EpsonLQ-2550

for /f "usebackq delims==. tokens=1-3" %%a in (`set targetPrinter`) do (
net print %localIP%\%%c findstr "%username%" >> testFile.txt
)

for /f "tokens=1-2 delims= " %%a in ('type testFile.txt') do net print %localIP% %%b /DELETE
del testFile.txt
exit

Currently, this is triggered by Windows Task Scheduler at a specific time of the day.
Hopefully, it will be helpful to you. So, happy Purging :D

Rey