Yesterday explained how to restart spoolsv server (printer spooler) if it exceeds 40MB of memory.
Sometimes spooler service will hang and there will not be high memory consumption, so we would need to detect that problem as well. For this scenario I have written the following script:
net start | findstr /i Spooler > nul
if not errorlevel 1 goto end
net stop Spooler
sleep 2
net start Spooler
:end
exit
I created a scheduled task to run this script under system every minute, for 24 hours a day. If spoolsv is OK, the script will just close, and if it is in error state, the script will restart the printer spooler service.

