JSI Tip 5200. How do I purge documents from a print queue, using a command?


In tip 1456, I described the net print command, which can be used to list the documents in a print queue, and to hold, release, and delete individual print jobs.

I have scripted DelPrint.bat to purge all the documents from a print queue, or optionally, all the documents submitted by a specific user.

The syntax for using DelPrint.bat is:

DelPrint ComputerName PrinterShare \[UserName\]

where:

ComputerName is the print 'server'. A leading \\ is optional.
PrinterSharer     is the print share name.
UserName is the optional user name. If omitted, all documents are purged.

DelPrint.bat contains:

@echo off
setlocal
if \{%2\}==\{\} goto syntax
set computer=%1
set queue=%2
set user=%3
if defined user set user=%user:"=%
set computer=%computer:"=%
set computer=%computer:\=%
set queue=%queue:"=%
set print="\\%computer%\%queue%"
for /f "Skip=8 Tokens=*" %%p in ('net print %print%') do set entry=%%p&call :purge
endlocal
goto :EOF
:syntax
@echo Syntax: DelPrint \\Server PrintQue \[UserName\]
endlocal
goto :EOF
:stripown
set owner=%owner:"=%
set owner=%owner:    ##=##%
set owner=%owner:   ##=##%
set owner=%owner:  ##=##%
set owner=%owner: ##=##%
goto :EOF
:stripent
set entry=%entry:"=%
set entry=%entry:##   =##%
set entry=%entry:##  =##%
set entry=%entry:## =##%
goto :EOF
:purge
if /i "%entry:~0,21%" EQU "The command completed" goto :EOF
set owner=%entry:~0,20%##
set entry=##%entry:~22,7%
:chkowner
set work=%owner: ##=##%
if not "%work%" EQU "%owner%" call :stripown "%owner%"&goto chkowner
set owner=%owner:##=%
:chkentry
set work=%entry:## =##%
if not "%work%" EQU "%entry%" call :stripent "%entry%"&goto chkentry
set entry=%entry:##=%
if not defined user goto delete
if /i not "%user%" EQU "%owner%" goto :EOF
:delete 
net print "\\%computer%" %entry% /delete>nul 2>&1


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish