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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete print jobs from a print queue

Status
Not open for further replies.

freavis

MIS
Feb 5, 2002
19
0
0
US
I have a print queue set up to save print jobs after printing for accounting purposes. I need a script that will delete jobs older that a specified date from that queue. Any ideas/code would be greatly appreciated.
Thanks
 
Hope this helps

The following code will read a files attributes identifying the date and time it was created, it will then strip the date, then it converts it to julian format (numdate)(a numerical number where 1 = 31/12/1899), take todays date and change that to julian format (today) compare the two dates minusing 60 days from today. delete any file that is 60 days or older .

Set fso =Wscript.CreateObject("Scripting.FileSystemObject")
set ofile = fso.GetFile("c:\yellow20.206")
sdate = Left(ofile.Datecreated,10)
DtDate = Cdate(sdate)
numdate = CDbl(Dtdate)
stoday = Cdate(Date())
today = CDbl(stoday)
If numdate < today - &quot;60&quot; Then
msgbox &quot;delete File&quot;
Else
msgbox &quot;keep File&quot;
End If

Now presuming that you are trying to read from a print queue and not from a list of files,

strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colPrintJobs = objWMIService.ExecQuery _
(&quot;Select * from Win32_PrintJob&quot;)
For Each objPrintJob in colPrintJobs
If objPrintJob.TimeSubmitted = xxxx Then
objPrintjob.Delete
End If
Next

strcomputer can be a remote computer name where the print queue is held

You will need to play with the If statement a bit and mya need some of the code from the top to verify the date and change it to julian format.
Sorry I don't have a printer attached currently to test any further.
Try putting MSGbox statements in to see the date so you know what you are playing with.

The second bit of code was taken from

and by looking at the WMI SDK



Regards
Steve Friday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top