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

RE: Printer usage by Daniel

Daniel
Thu Dec 01 07:37:22 CST 2005

Fixed.

In case anyone is refencing this posting the solution is (should I say my
solution was), my problem was were I placed the 'ObjFile.WriteLine addtxt'
inside the loop function that was giving me my issue :

*****************
strComputer = "."
Const FOR_APPENDING = 8
LogFileName = "ptclaire7_prn2c.Log"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecNotificationQuery("Select * From
__InstanceCreationEvent " & "Within 5 Where TargetInstance ISA
'Win32_PrintJob'")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(LogFileName, FOR_APPENDING, True)

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
*****************

Daniel





"Daniel" wrote:

> 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

RE: Printer usage by Daniel

Daniel
Thu Dec 01 07:41:04 CST 2005

I spoke too soon! The issue remains... I still need some advise on this one!








"Daniel" wrote:

> Fixed.
>
> In case anyone is refencing this posting the solution is (should I say my
> solution was), my problem was were I placed the 'ObjFile.WriteLine addtxt'
> inside the loop function that was giving me my issue :
>
> *****************
> strComputer = "."
> Const FOR_APPENDING = 8
> LogFileName = "ptclaire7_prn2c.Log"
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colPrintJobs = objWMIService.ExecNotificationQuery("Select * From
> __InstanceCreationEvent " & "Within 5 Where TargetInstance ISA
> 'Win32_PrintJob'")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(LogFileName, FOR_APPENDING, True)
>
> 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
> *****************
>
> Daniel
>
>
>
>
>
> "Daniel" wrote:
>
> > 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