script to restart print spooler service


The below VB script can be used to restart print spooler service at regular intervals with Windows task scheduler.

'======================================
'This script serves as a workaround to poorly written printer drivers
'                   
'It checks the spooler folder to see if there are any active jobs.
'If it is empty it will restart the spooler service.
'It works best as a regularly scheduled task.                   
'======================================  

Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

If objFSO.FolderExists("C:\Windows\system32\spool\PRINTERS") Then
  Set objFolder = objFSO.GetFolder("C:\Windows\system32\spool\PRINTERS")

  If objFolder.Files.Count = 0 And objFolder.SubFolders.Count = 0 Then
objShell.Run "Net Stop Spooler", 0, True
objShell.Run "Net Start Spooler", 0, True
  Else
  End If
End If