Wednesday, April 29, 2009

Restart Citrix Print Manager Service on spooler crash

When Windows Print Spooler crashes, Citrix Print Manager Service becomes lost in space and session printers are no longer created. Here is a little .bat file to restart the Windows print spooler and the Citrix Print Manager Service automatically when the print spooler crashes. Obviously this does not fix the root issue of the spooler service crashing.


Save as AutoSet-RestartCitrixPrintSpoolerOnCrash.bat and run it directly or attach it to a GPO. Then go to Services.msc -> Print Spooler -> Properties -> Recovery Tab to view the results. Magic!


: RestartCitrixPrintSpoolerOnCrash.bat
@echo off


set SvcRestartCmd=C:\WINDOWS\system32\RestartCitrixPrintSpooler.bat

if _%1_==_/force_ goto :force
if _%1_==_/Force_ goto :force

if exist %SvcRestartCmd% goto :already

goto :begin

:force
echo Forcing script to run

:begin
echo @echo off >%SvcRestartCmd%
echo net stop cpsvc >>%SvcRestartCmd%
echo net stop spooler >>%SvcRestartCmd%
echo net start spooler >>%SvcRestartCmd%
echo net start cpsvc >>%SvcRestartCmd%

sc.exe failure spooler reset= INFINITE actions= run/0/run/0/run/0 command= %SvcRestartCmd%

goto :end

:already
echo Script RestartCitrixPrintSpooler.bat exists already
echo My work is done - exiting
echo use the /Force option to force script to run
:end