Good morning,
I have the following script that tracks a specific printer's usage.
Originally it used a wscript.echo to notify me but I am trying to make it log
the usege to a file instead. The problem is that using different
permutations I have been unable to get the script to produce a proper log.
Either it doesn't log anything or else it logs the same print job a multitude
of times. Can someone help me fix/debug my script.
*************
strComputer = "."
Const FOR_APPENDING = 8
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
LogFileName = "ptclaire7_prn2c.Log"
Set objFile = objFSO.OpenTextFile(LogFileName,FOR_APPENDING,True)
Set colPrintJobs = objWMIService. _
ExecNotificationQuery("Select * From __InstanceCreationEvent " & "Within
5 Where TargetInstance ISA 'Win32_PrintJob'")
Do While True
Set objPrintJob = colPrintJobs.NextEvent
If InStr(objPrintJob.TargetInstance.Name, "ptclaire7_prn2c") Then
addtxt = objPrintJob.TargetInstance.Owner & " - " &
objPrintJob.TargetInstance.TotalPages & " - " &
objPrintJob.TargetInstance.PagesPrinted & " - " &
objPrintJob.TargetInstance.Document
End If
ObjFile.WriteLine addtxt
Loop
*************
Thank you,
Daniel