WhoKilledKenny
MIS
I know that VBScript and Win2000 Server printing are not popular issues. I know most suggestion would be to upgrade to Win2003, as was my suggestion. Let's just say that is not an option right now.
What I am trying to accomplish. We have a pharmacy print queue (in a pool of two printers) with a requirement to save the jobs in the queue. This is to allow pharamcy techs to look into the queue to verify printed jobs as well as any errors. Not a problem... we just used save print jobs after printing check box option on the queue.
I was tasked to write a script that will enumerate the queue and delete print jobs with the status of Printed. Therefore only jobs with error status will stay in the queue. Now I was able to create the script, which is posted below. It works but has one problem... when the queue gets to a certain size the script hangs and doesn't complete. Would you mind looking at the code and post questions and or possible solutions?
What I am trying to accomplish. We have a pharmacy print queue (in a pool of two printers) with a requirement to save the jobs in the queue. This is to allow pharamcy techs to look into the queue to verify printed jobs as well as any errors. Not a problem... we just used save print jobs after printing check box option on the queue.
I was tasked to write a script that will enumerate the queue and delete print jobs with the status of Printed. Therefore only jobs with error status will stay in the queue. Now I was able to create the script, which is posted below. It works but has one problem... when the queue gets to a certain size the script hangs and doesn't complete. Would you mind looking at the code and post questions and or possible solutions?
Code:
'* FileName: RxPrintPurge_v2.vbs
'*=============================================================================
'* Script Name: [RxPrintPurge]
'* Created: [5/4/2007]
'* Author: Jesse Hamrick
'* Company: XXXXXXXXXXXXXXXX
'* Email: JHmarick@whokilledkenny.net
'* Web: [URL unfurl="true"]http://www.whokilledkenny.net[/URL]
'* Reqrmnts:
'* Keywords: \\ServerName\PrinterName
'*=============================================================================
'* Purpose: Managing Pharmacy Rx Print Orders. Phamacy Print Queue is
'* configured to keep all print jobs in queue. This is to verify
'* which jobs were printed and which jobs may have errors.
'*=============================================================================
'*=============================================================================
'* DECLARE VARIABLES
'*=============================================================================
Dim strComputer, objWMIService, colPrintedJobs, objPrintJob
Dim JobID, objShell
Dim arrJobID()
intSize = 0
On Error Resume Next
strComputer = "ServerName"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintedJobs = objWMIService.ExecQuery("Select * From Win32_PrintJob")
For Each objPrintJob In colPrintedJobs
If objPrintJob.StatusMask = 128 Then
ReDim Preserve arrJobID(intSize)
arrJobID(intSize) = objPrintJob.JobID
intSize = intSize + 1
WScript.Echo "Name: " & objPrintJob.Document & " "_
& "Job ID: " & objPrintJob.JobId & " " & "Job Status: " & objPrintJob.JobStatus
End If
Next
For i = LBound(arrJobID) To UBound(arrJobID)
WScript.Echo arrJobID(i)
Next
Set colPrintedJobs = Nothing
NetPrint
'*=============================================================================
'* SUBROUTINES OR FUNCTION LISTINGS
'*=============================================================================
'*=============================================================================
'* Subroutine: NetPrint
'* Created: [5/4/2007]
'* Author: Jesse Hamrick
'* Arguments:
'*=============================================================================
'* Purpose: Subroutine launches command prompt and runs the "Net Print"
'* Command. Deletes Print Jobs based on JobID's stored in the
'* JobID Array. Jobs are placed in the array based on the status
'* "Printed." cmd- Net Print \\ServerName job# /Delete
'*=============================================================================
Sub NetPrint
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
For Each JobID In arrJobID
objShell.Run("%comspec% /c Net Print \\" & strComputer & " " & JobID & " /DELETE"), 06, True
Next
Set objShell = Nothing
End Sub
'*=============================================================================
'* END OF SCRIPT:
'*=============================================================================