You are on page 1of 1

:Initialise

@Setlocal
@Set SpoolerDir="%comspec:cmd.exe=%spool\printers"

:Start
@>nul 2>nul dir /a-d "%SpoolerDir%\*" && (goto CheckPrivileges)
@Echo No file(s) found in Spooler Print directory :
@Echo %SpoolerDir%
@Echo.
@goto Halt

:CheckPrivileges
@Rem Check user has elevated admin privileges by forcing condition test.
@NET FILE 1>NUL 2>NUL
@if '%errorlevel%'=='0' goto AllOk
@Echo Batch file must be run as Administrator
@Echo to allow Spooler Service to Reset.
@Echo.
@goto Halt

:AllOk
@Rem @Echo Deleting all Print Files in :
@Rem @Echo %SpoolerDir%
@Rem Remove unwanted DIR headings.
@echo --- Date ---- Time -------------- Size ---- Owner -------------- File Name ---
@FOR /f "tokens=*" %%D IN ('dir /q /a-d %spoolerdir%\*.* ^| find "/"') DO echo %%D
@Echo.

:MainExecution
@Net stop spooler
@Del /F /Q %SpoolerDir%\*.*
@Echo All Spooler Print files deleted....
@Echo.
@Net start spooler
@Echo.

:Remaining
@Rem Show if any corrupt files still remaining in Spooler directory.
@>nul 2>nul dir /a-d "%SpoolerDir%\*" || (goto Halt)
@Echo Files Still Remaining in Spooler Directory :
@Echo -------------------------------------------
@Dir %SpoolerDir% /b
@Echo.

:Halt
@EndLocal
@pause

You might also like