Jump to content

Print Queue Monitor


Smitro
 Share

Recommended Posts

Hi all,

I'm in the middle of writing a print queue monitor. I would like to be able to run this on our print server to be able to track who's printing large amounts and reduce the effect on the environment.

I've done a fair chunck of it, but I'm finding that it's causing a bit of a load on the CPU. On average the 'spoolsv.exe' process sits at about 15-20% constantly when nothing is happening. I'm wondering if there is a way I can reduce this.

I'm using the following code to access the print queue.

; Connect to Print Queue
$objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
 
While 1
 
  $AllPrintJobs = $objWMIService.ExecQuery ("SELECT * FROM Win32_PrintJob")
 
  ; Run through Print Jobs
  For $PrintJob In $AllPrintJobs
 
  ; Process any new jobs here
 
  Next 

Sleep (50)
WEnd

I've found that I have to catch the job several times in the queue. If I don't I can miss the total number of pages as the jobs spools.

Is there another way of me getting the same information? Does the information go to another location after the print queue?

Link to comment
Share on other sites

I think I might have found a way to do this...

It can be logged in the event viewer. For Server 2008 R2 and Win7 you can log it here:

Applications and Service Logs -> Microsoft -> Windows -> Print Service -> Operational

So I need to be able to grab the information from there and import it into my database so I can play with the data.

I've found _EventLog__Open() _EventLog__Read() and in the help, but how do I reference that log?

Link to comment
Share on other sites

  • 4 months later...

Hi,

any results till now?

I look for a solution to read this Windows 7 or 2008 "Print Service" eventlog too. Have Autoit 3.3.7.23 (beta).

It seems to me, that Autoit can not access the eventlog "Microsoft-Windows-PrintService/Operational" directly. :-(

See theads:

A workaround shows this thead, but I don't want to edit the Registry to help Autoit to access this event log, so this is no solution for me:

Until now, I see only a chance to access this logs by using PowerShell (not prefered) or with "wevtutil qe Microsoft-Windows-PrintService/Operational".

Is there really no way to get access to this eventlog elegantly with Autoit without using external programs?

Regards

Trash

Link to comment
Share on other sites

  • Moderators

The helpfile shows an excellent example under _EventLog_Read which allows you to return the last event in a log as an array. From this, you should easily be able to pull the data you want into your db.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

The helpfile shows an excellent example under _EventLog_Read which allows you to return the last event in a log as an array. From this, you should easily be able to pull the data you want into your db.

Yes, I tryed this already, but it seems that Autoit can only access the "standard" eventlogs (the 4-5 eventlogs since Windows 2000) and not the much more eventlogs of Vista/7/2008. :-(

Here is the example from helpfile for "_EventLog_Read". I only changed the name of the eventlog to "Microsoft-Windows-PrintService/Operational".

If you try this (first activate this log "Operational" in your eventviewer and print something, to get events) , then you get only entries from the "Application" log:

#include <GuiConstantsEx.au3>
#include <EventLog.au3>
Global $iMemo
_Main()
Func _Main()
Local $hEventLog, $hGUI, $aEvent
; Create GUI
$hGUI = GUICreate("EventLog", 400, 300)
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 300, 0)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; Read most current event record
$hEventLog = _EventLog__Open("", "Microsoft-Windows-PrintService/Operational")
$aEvent = _EventLog__Read($hEventLog, True, False) ; read last event
;~  $hEventLog = _EventLog__Open("", "System")
;~  $aEvent = _EventLog__Read($hEventLog)
;~  $aEvent = _EventLog__Read($hEventLog, True, False)
MemoWrite("Result ............: " & $aEvent[ 0])
MemoWrite("Record number .....: " & $aEvent[ 1])
MemoWrite("Submitted .........: " & $aEvent[ 2] & " " & $aEvent[ 3])
MemoWrite("Generated .........: " & $aEvent[ 4] & " " & $aEvent[ 5])
MemoWrite("Event ID ..........: " & $aEvent[ 6])
MemoWrite("Type ..............: " & $aEvent[ 8])
MemoWrite("Category ..........: " & $aEvent[ 9])
MemoWrite("Source ............: " & $aEvent[10])
MemoWrite("Computer ..........: " & $aEvent[11])
MemoWrite("Username ..........: " & $aEvent[12])
MemoWrite("Description .......: " & $aEvent[13])
_EventLog__Close($hEventLog)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main
; Write a line to the memo control
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

This is mentioned in other threads too. Please see the last posts of my linked threads above...

Regards

Edited by Trash
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...