JSI Tip 5200. How do I purge documents from a print queue, using a command?
Jerold Schulman
April 21, 2002
1 Min Read
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 offsetlocalif {%2}=={} goto syntaxset computer=%1set queue=%2set user=%3if 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 :purgeendlocalgoto :EOF:syntax@echo Syntax: DelPrint \Server PrintQue [UserName]endlocalgoto :EOF:stripownset owner=%owner:"=%set owner=%owner: ##=##%set owner=%owner: ##=##%set owner=%owner: ##=##%set owner=%owner: ##=##%goto :EOF:stripentset entry=%entry:"=%set entry=%entry:## =##%set entry=%entry:## =##%set entry=%entry:## =##%goto :EOF:purgeif /i "%entry:~0,21%" EQU "The command completed" goto :EOFset owner=%entry:~0,20%##set entry=##%entry:~22,7%:chkownerset work=%owner: ##=##%if not "%work%" EQU "%owner%" call :stripown "%owner%"&goto chkownerset owner=%owner:##=%:chkentryset work=%entry:## =##%if not "%work%" EQU "%entry%" call :stripent "%entry%"&goto chkentryset entry=%entry:##=%if not defined user goto deleteif /i not "%user%" EQU "%owner%" goto :EOF:delete net print "\%computer%" %entry% /delete>nul 2>&1
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like