Tuesday, March 13, 2012

Remote CMD reset spooler


(thanks to http://www.gameaddict.eu/tag/how-to-fix-a-printer-spooler-error/ for this tip)

Remote CMD reset spooler – you need to have administrative privileges on the remote computer. The script can be used to restart the spooler on remote computer systems.


sc \\computername query spooler | find /I “STATE” | find /I “stopped”
if “%ERRORLEVEL%”==”1″ (sc \\computername stop spooler) ELSE GOTO NEXT

REM the Computer Name can be replaced by the computer’s IP address.
REM So the first command is querying the spooler and pipes the information to
REM second command to find the state, which is piping the information to the IF statement
REM the IF statement will make the decision what to do and pass the next execution to display on the screen the next message after @echo

@echo The Spooler is stopped Mapping the Jobs folder to delete the temp files

REM The next line maps a network folder because Command Line doesn’t understand UNC paths
REM Then you need to delete the jobs, which can be deleted easily since we made sure the print Spooler is not started.

net use x: \\computername\C$\windows\system32\spool\printers

REM After mapping the network drive, we are accessing it in the next line.

x:

REM now we are able to execute the deletion of the spooled files with “del /q *.*”.
del /q *.*

REM Un-mapping the network drive “net use /delete x:” Then starting the Print Spooler
net use /delete x:
sc \\computername start spooler

REM Querring the spooler to see if its running. But here the Window might exit.

sc \\computername query spooler | find /I “STATE” | if /I “%STATE%”==”RUNNING” @echo Spooler has been started