Hmm... There's a problem in there alright but I realised the formatting wasn't helping with tabs, etc.. so I've reformatted and edited a little..
Code:
' This script looks for printjobs that have "started" but essentially hung the print queue
' Key triggers are the PrintJob.StartTime
' If this is greater than the period set then the script will delete that job
' and restart the print spooler.
'
'
' Author: Martin Smallridge, 06/02/07
' Using code from
' http://www.activexperts.com/activmon...nting/servers/
'On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Dim computerName
computerName = LCase(WshNetwork.ComputerName)
' Define the names of the Services
sService1 = "LPDSVC"
sService2 = "Spooler"
Const USE_LOCAL_TIME = True
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, TimeSubmitted, Total Pages, Time In Queue"
For Each objPrintJob in colPrintJobs
DateTime.Value = objPrintJob.StartTime
dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
TimeinQueue = DateDiff("n", dtmActualTime, Now)
If TimeinQueue > 15 Then
strPrinterName = Split(objPrintJob.Name,",",-1,1)
Wscript.Echo strPrinterName(0) & ", " _
& objPrintJob.JobID & ", " & dtmActualTime & ", " & _
objPrintJob.TotalPages & ", " & TimeinQueue
'stop services
WshShell.Run "net stop " & sService1,1,TRUE
WshShell.Run "net stop " & sService2,1,TRUE
'Delete this job
objPrintJob.Delete_
'start services
shShell.Run "net start " & sService1,1,TRUE
WshShell.Run "net start " & sService2,1,TRUE
End If
Next The idea is ultimately to run every 30 minutes to remove any stalled processes because that tends to be what happens.
I've used the DateTime.Value = objPrintJob.StartTime value rather than the original "TimeSubmitted" because I'm only looking to remove the problem job so the others in the queue can carry on but not sure if that's what will actually happen at present :P