+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Printer Queue - stalled job killer in Coding and Web Development; At present I'm waiting to see if this script works when the conditions present themselves (ie: a stalled print queue) ...
  1. #1
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Printer Queue - stalled job killer

    At present I'm waiting to see if this script works when the conditions present themselves (ie: a stalled print queue) so consider it draft #1.




    Code:
    ' This script looks for printjobs that have "started" but essentially hung the print queue
    ' Key triggers are 
    '  - PrintJob.TimeSubmitted
    '  - PrintJob.StatusMask
    '  - JobPosition (customDim)
    '
    ' If the job is more than 15 minutes old, has a "printing" status 
    ' and is the first job in the queue 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, Time Submitted, Total Pages"
    
    Dim JobPosition
    JobPosition = 1
    
    For Each objPrintJob in colPrintJobs
      DateTime.Value = objPrinter.TimeSubmitted
      dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
      TimeSinceSubmit = DateDiff("n", dtmActualTime, Now)
      If TimeSinceSubmit > 15 And objPrintJob.StatusMask = 16 And JobPosition < 2 Then
      	
        strPrinterName = Split(objPrintJob.Name,",",-1,1)
        Wscript.Echo strPrinterName(0) & ", " _
    			& objPrintJob.JobID & ", " & dtmActualTime & ", " _
          & objPrintJob.TotalPages & ", " & TimeSinceSubmit
    
        'stop services
        WshShell.Run "net stop " & sService1,1,TRUE
        WshShell.Run "net stop " & sService2,1,TRUE
    
        'Delete this job
        objPrintJob.Delete_
    
        'start services
        WshShell.Run "net start " & sService1,1,TRUE
        WshShell.Run "net start " & sService2,1,TRUE
    
      End If
      JobPosition = JobPosition + 1		
      ' We only want to kill Job #1 if it's stalled
      ' so if we make it past job #1 it's working
    Next

    Like I said, no idea if this works as yet but I'll update once I get a chance to try it against the conditions we hit here every few days... ie: a stalled print queue.
    Last edited by contink; 18th March 2008 at 02:52 PM. Reason: quick fix

  2. #2

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,274
    Thank Post
    614
    Thanked 1,567 Times in 1,407 Posts
    Rep Power
    412

    Re: Printer Queue - stalled job killer

    I think

    Code:
    Dim JobPosition = 1
    Should be:

    Code:
    Dim JobPosition
    JobPosition = 1
    Ben

  3. #3
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Printer Queue - stalled job killer

    After waiting a while for someone to kill the print queue I finally got a chance to test this out properly and ended up re-writing the thing to handle things properly.

    The script now tries a couple of things.

    1. It tests the print queue to see if there's any print jobs either stalled or taking too long to complete (set as the "StallTime" variable).

    2. If yes it then forces the print spooler to get restarted

    3. If the job is still "stalled" or running after StallTime + 15 minutes it kills the spooler, deletes the stalled job and then restarts the spooler.


    Of course this could result in someone ending up with a print job that would take considerable time to complete having it kicked off the system after so many minutes. Perhaps not ideal but having seen a school printer hogged for over an hour in the past I actually think it has a salutory effect on printer usage.

    One workaround is to set the scheduling system so that you leave a window during lunchtimes, before class and after school when the script doesn't run as an auto schedule routine.


    Anyway, comments welcome and especially any suggestions for reducing the load.. I know it's a clutz like approach so any slimming techniques would be useful
    Attached Files Attached Files

  4. #4
    Midget's Avatar
    Join Date
    Oct 2006
    Location
    In a Server Room cutting through a forest of Cat5e
    Posts
    1,298
    Thank Post
    5
    Thanked 59 Times in 49 Posts
    Rep Power
    39

    Re: Printer Queue - stalled job killer

    I get an error on Set DateTime = CreateObject("WbemScripting.SWbemDateTime")

    ActiveX component can't create object


    when using Windows 2000Server

  5. #5
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Printer Queue - stalled job killer

    Quote Originally Posted by Midget
    I get an error on Set DateTime = CreateObject("WbemScripting.SWbemDateTime")

    ActiveX component can't create object


    when using Windows 2000Server
    Hmm.. may be win2k related then as I'm running it on a Win2k3 server..

    Problem is I know very little about VBscript so I'll hope someone else can shed some light on the problem.

  6. #6
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Printer Queue - stalled job killer

    This forum post (Cached because Nyorks filter blocks forums)..

    http://66.102.9.104/search?q=cache:t...gl=uk&safe=vss

    ... provides some clues as to why... it does seem to be a win2k problem.

  7. #7
    Midget's Avatar
    Join Date
    Oct 2006
    Location
    In a Server Room cutting through a forest of Cat5e
    Posts
    1,298
    Thank Post
    5
    Thanked 59 Times in 49 Posts
    Rep Power
    39

    Re: Printer Queue - stalled job killer

    ahhh thats ok then, as you were.

    /me goes off to ask for a new server

  8. #8
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Printer Queue - stalled job killer

    Quote Originally Posted by Midget
    ahhh thats ok then, as you were.

    /me goes off to ask for a new server
    LOL... good luck selling that one as the reason...

    If I figure out what the differences are and how to do a comparison between the two dates I'll write that in but right now I know my limits.. (see that dot on the horizon behind me, that's the line.. )

  9. #9

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,274
    Thank Post
    614
    Thanked 1,567 Times in 1,407 Posts
    Rep Power
    412

    Re: Printer Queue - stalled job killer

    I get the exact same error on my win2k print server.

    It's going to be replaced this year with a 2003 one or possible pykota if all my printers work with it.

    Ben

  10. #10
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Printer Queue - stalled job killer

    Seems I need to do a little more work on this script as a bug appeared with it.

    It'd appear that the script killed a print queue at some point but then failed to restart it again.

    I need to think about how best to avoid that little problem but basically it's a current "feature" that you need to be aware of.

SHARE:
+ Post New Thread

Similar Threads

  1. Killer WiFi
    By eduabncs in forum Jokes/Interweb Things
    Replies: 13
    Last Post: 21st September 2009, 06:59 PM
  2. Replies: 9
    Last Post: 26th February 2007, 12:45 PM
  3. Exchange mailserver queue is in the 1000s?
    By Jake in forum General Chat
    Replies: 15
    Last Post: 23rd January 2007, 06:57 PM
  4. Replies: 10
    Last Post: 19th December 2006, 09:42 AM
  5. Printer queue control for teachers
    By NetworkGeezer in forum How do you do....it?
    Replies: 11
    Last Post: 17th May 2006, 04:30 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •