![]() | Register | FAQ | Members | Social Groups | User Map | Calendar | Search | Today's Posts | Mark Forums Read |
| | | LinkBack | Thread Tools | Search Thread | Language |
| Sponsored Links |
| | #1 |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | It seems one or two print jobs like to choke the print queue for one print server and I was wondering if anyone had come up with a script that could be used to isolate a stalled printjob and delete it from the queue. Anyone come across anything along these lines at all? |
| |
| | #2 |
![]() Join Date: Oct 2006 Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 | I have this script to do it, but i run it manually instead of on a schedule. I suppose putting it on a schedule over lunch and at night would make sence, but not sure how to make it just remove the stalled jobs (this removes all jobs). oh btw PCPrintLogger is my ...print logger.............. Code: ' Define the names of the Services
sService1 = "LPDSVC"
sService2 = "PCPrintLogger"
sService3 = "Spooler"
' Create a shell object.
Set WshShell = WScript.CreateObject("WScript.Shell")
'stop services
WshShell.Run "net stop " & sService1,1,TRUE
WshShell.Run "net stop " & sService2,1,TRUE
WshShell.Run "net stop " & sService3,1,TRUE
'Delete Spool files
Set foo = CreateObject("Scripting.FileSystemObject")
foo.DeleteFile "C:\WINNT\system32\spool\PRINTERS\*.*"
'start services
WshShell.Run "net start " & sService1,1,TRUE
WshShell.Run "net start " & sService2,1,TRUE
WshShell.Run "net start " & sService3,1,TRUE
|
| |
| | #3 |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | Thanks Midge... that helps a lot to fill the blanks I had... So, along with this: http://www.activexperts.com/activmon...nting/servers/ ... I think I can probably cobble together something that looks for the job that's sitting there at the top of the queue and kill that on it's own so the rest of the queue can continue on.. |
| |
| | #4 |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | Hmm... still early days as yet because I have a clean queue and can't test but I thought I'd provide draft #1 of my script. 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_ 'Delete Spool files 'Set foo = CreateObject("Scripting.FileSystemObject") 'foo.DeleteFile "C:\WINNT\system32\spool\PRINTERS\*.*" 'start services shShell.Run "net start " & sService1,1,TRUE WshShell.Run "net start " & sService2,1,TRUE End If Next |
| |
| | #5 |
![]() Join Date: Oct 2006 Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 | How often will you run this script? From the brief skim I just did of it, it will delete ALL the jobs from ALL the printers. This might be a good thing if run at the end of each lesson, as the teacher probably won't care about the print jobs and it would just be a waste of paper, but just making sure you understand. |
| |
| | #6 |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | 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 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 |
| |
| | #7 |
![]() Join Date: Oct 2006 Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 | That's MUCH better now you've removed my line foo.DeleteFile "C:\WINNT\system32\spool\PRINTERS\*.*" Isn't a pain when you can't replicate faults so that you can test your solutions? |
| |
| | #8 | |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | Quote:
I know this isn't working as it is but I'll persuade some poor teacher to do lots of printing soon and then kill it all... ooooh my name will be spoken with such respect today I'm sure... 8) :twisted:Edit: Points to anyone who spotted the freudian slip earlier... | |
| |
| | #9 |
![]() Join Date: Oct 2006 Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 | Quick question, the datediff function, is it in seconds or minutes? Because if it is seconds then this will mean that hardly anyone will be allowed to print TimeinQueue = DateDiff("n", dtmActualTime, Now) If TimeinQueue > 15 Then |
| |
| | #10 | |
![]() Join Date: Jul 2006 Location: South Yorkshire
Posts: 2,807
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 | Quote:
| |
| |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need a script to delete shortcuts | philtomo-25 | Scripts | 2 | 01-11-2007 04:50 PM |
| Script to Delete Profiles - PLEASE HELP | Mr_M_Cox | Scripts | 10 | 13-06-2007 03:51 PM |
| Adding User Name To Print Jobs | Richie_OLSJ | Network and Classroom Management | 11 | 08-06-2007 10:55 AM |
| Redirecting print jobs | SteveBentley | How do you do....it? | 1 | 05-06-2007 11:56 AM |
| print manager logging jobs | alonebfg | Windows | 7 | 04-11-2006 10:12 PM |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search Thread |
|
|




:twisted:
