Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript and Win2000 Printing Issue 1

Status
Not open for further replies.
Apr 5, 2005
1,484
US
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?
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:
'*=============================================================================
 
Reduce your results to just the data you need.

Select * From Win32_PrintJob Where JobStatus = 'Printed'


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark...
I'm testing your suggestion. I have added the the line in the SELECT statement and have removed the "IF THEN" statement. I'll let you know my results from testing.

 
Results of testing:
Still seeing the same issue.
Once the queue gets over X amount of jobs (Let's say 100, I don't know the exact number), I get the following error:
Line (For Each objPrintJob In colPrintedJobs) (null): 0x80041001
Just from first glance, looks like there are no entries in the array. So I am reasearching.
Again, if you have any ideas or suggestions... please reply.
 
ok... Microsoft is looking at the Code.
Another stange thing. The print queue in question currently has over 400 documents with the status of "Printed." I set up another print queue (same print server) and sent a test page. It's status is "Printed." Ran the script and it added the job, from the print queue with one job in it, to the collection. The original Print Queue still errors with NULL. Seems to be and issue with the number of print jobs in the queue.
I'll keep you all updated...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top