Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Coding
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 26-02-2007, 11:09 AM   #1
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default scheduled script to delete stalled print jobs?

Thought I'd put this one out to you all as it's becoming a prevelant problem on one school network.

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?
  Reply With Quote
Old 26-02-2007, 11:37 AM   #2
 
Midget's Avatar
 
Join Date: Oct 2006
Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
uk uk wales
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 Midget is on a distinguished road
Default Re: scheduled script to delete stalled print jobs?

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
  Reply With Quote
Old 26-02-2007, 12:18 PM   #3
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default Re: scheduled script to delete stalled print jobs?

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..
  Reply With Quote
Old 26-02-2007, 01:07 PM   #4
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default Re: scheduled script to delete stalled print jobs?

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
Not entirely sure if the job will be available for deletion or if indeed this approach will work yet but like I said, early days...
  Reply With Quote
Old 26-02-2007, 01:13 PM   #5
 
Midget's Avatar
 
Join Date: Oct 2006
Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
uk uk wales
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 Midget is on a distinguished road
Default Re: scheduled script to delete stalled print jobs?

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.
  Reply With Quote
Old 26-02-2007, 01:27 PM   #6
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default Re: scheduled script to delete stalled print jobs?

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
  Reply With Quote
Old 26-02-2007, 01:29 PM   #7
 
Midget's Avatar
 
Join Date: Oct 2006
Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
uk uk wales
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 Midget is on a distinguished road
Default Re: scheduled script to delete stalled print jobs?

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?
  Reply With Quote
Old 26-02-2007, 01:34 PM   #8
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default Re: scheduled script to delete stalled print jobs?

Quote:
Originally Posted by Midget
Isn't a pain when you can't replicate faults so that you can test your solutions?
Ain't that the truth... Where's a bug when you need one eh?

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...
  Reply With Quote
Old 26-02-2007, 01:39 PM   #9
 
Midget's Avatar
 
Join Date: Oct 2006
Location: In a Server Room cutting through a forest of Cat5e
Posts: 1,024
uk uk wales
Thanks: 1
Thanked 6 Times in 6 Posts
Rep Power: 8 Midget is on a distinguished road
Default Re: scheduled script to delete stalled print jobs?

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
  Reply With Quote
Old 26-02-2007, 01:45 PM   #10
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,807
uk uk yorkshire
Thanks: 108
Thanked 109 Times in 81 Posts
Rep Power: 34 contink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to beholdcontink is a splendid one to behold
Default Re: scheduled script to delete stalled print jobs?

Quote:
Originally Posted by Midget
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
The "n" determines that it should be in minutes (no preceding 0) so that's covered
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
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
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 11:04 PM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net