Jump to content
Sign in to follow this  
Smitro

Print Queue Monitor

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?

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.


"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!

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Bilgus
      Went looking for a FIFO queue there are a few examples here on the forum but I didn't like the complexit/lack of flexibility in what I found
      The Queue Ive implemented uses a single dimension array  set up as a circular buffer
      The position and Item Count are stored in an extra slot of the array inside a 'DllStruct'
      Convenience Functions are included
      FifoQueue_Create($iSlots) ;Initialize the Queue Func FifoQueue_($eFQ, ByRef $aQ) ;For Status Functions - (So you don't have to supply $vOut) Available operations:
      $eFQ_Create = 0, $eFQ_Push, $eFQ_Peek, $eFQ_Pop, $eFQ_IsEmpty, $eFQ_IsFull, $eFQ_Count, $eFQ_Empty, $eFQ_IsInit Example (With Debug function)
       
    • By Chimp
      This is a simple implementation of two stacks, one of FIFO type and the other of LIFO type.

      Both are based on the script.dictionary object and are self contained in two functions.
      If you call the function by passing an element as a parameter, that element is pushed on the stack,
      if you call the function without parameters, an element is retrieved (and removed) from the stack.
      both functions are used in the same way, the only difference is the order in which the data is returned, that is
      First In First Out for the _FIFO() function
      Last In First Out for the _LIFO() function
      here the two functions in its simplest form just to better see how they work. (see below for another version and example of use)
      Func _FIFO($vItem = '') Static Local $oFIFOStack = ObjCreate("Scripting.Dictionary") Static Local $iNDX = 1 Local $vPull = '' If $vItem = '' Then ; no Item to push, just pull from stack then If $oFIFOStack.Count Then ; ensure stack is not empty $vPull = $oFIFOStack.Item($iNDX) ; get the first item still in stack $oFIFOStack.Remove($iNDX) ; remove item from stack $iNDX += 1 ; raise the bottom index Return SetError(0, $oFIFOStack.Count, $vPull) ; return item to caller Else Return SetError(1, 0, '') EndIf Else $oFIFOStack.ADD($oFIFOStack.Count + $iNDX, $vItem) ; Add item SetExtended($oFIFOStack.Count) EndIf EndFunc ;==>_FIFO Func _LIFO($vItem = '') Static Local $oLIFOStack = ObjCreate("Scripting.Dictionary") Local $vPull = '' If $vItem = '' Then ; no Item to stack, just pull from stack then If $oLIFOStack.Count Then ; ensure stack is not empty $vPull = $oLIFOStack.Item($oLIFOStack.Count) ; get the top item $oLIFOStack.Remove($oLIFOStack.Count) ; remove item from stack Return SetError(0, $oLIFOStack.Count, $vPull) ; return item to caller Else Return SetError(1, 0, '') EndIf Else $oLIFOStack.ADD($oLIFOStack.Count + 1, $vItem) ; Add item SetExtended($oLIFOStack.Count) EndIf EndFunc ;==>_LIFO for a more convenient way of use, here below, there is a version that allows a  way to get the Count property, and to perform the RemoveAll method by the use of  an optional second parameter. See function header for more infos
      Have fun
      ; Example of FIFO stack: data keeps same order ConsoleWrite('FIFO example' & @CRLF & 'Push Data' & @CRLF) For $i = 1 To 50 ConsoleWrite($i & ' ') _FIFO($i) ; push $i in the stack Next ConsoleWrite(@CRLF & 'Pull Data' & @CRLF) For $i = 1 To _FIFO('', 3) ; _FIFO('', 3) return Count ConsoleWrite(_FIFO() & ' ') ; pull data & print it Next ; Example of LIFO stack: data returned in reverted order ConsoleWrite(@CRLF & @CRLF & 'LIFO example' & @CRLF & 'Push Data' & @CRLF) For $i = 1 To 50 ConsoleWrite($i & ' ') _LIFO($i) ; push $i in the stack Next ConsoleWrite(@CRLF & 'Pull Data' & @CRLF) For $i = 1 To _LIFO('', 3) ; _LIFO('', 3) return Count ConsoleWrite(_LIFO() & ' ') ; pull data & print it Next ConsoleWrite(@CRLF & @CRLF) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FIFO ; Description ...: A simple implementation of a FIFO stack (can be used to pull or push data from/to the stack) ; ; Syntax ........: _FIFO([$vItem = ''[, $vServiceCall = False]]) ; Parameters ....: $vItem - [optional] A variant value. Default is ''. ; this parameter can be empty or filled with data and behaves like: ; - if empty: the function pulls and return data from the stack ; - if filled: the function push that data to te stack ; $vServiceCall - [optional] A KeyWord or a value. Default is False. ; this parameter allows to perform some internal "methods" ; Note: When this parameter is used the previous parameter $vItem is simply ignored. ; 'Default' or 1 : Reindex the Key Names starting from 1 (internal use) ; 'Null' or 2 : Remove all items from the stack ; 'True' or 3 : Returns only the number of elements stored in the stack (returns 0 if stack is empty) ; ; Return values .: - when the function is used to Push data: ; returns nothing ; set @extended with the new total number of elements in the stack ; - when the function is used to Pull data: ; returns the pulled data (and removes it from the stack) ; set @extended with the number of elements still in the stack. ; If you try to pull data from an empty stack you get an empty string and @error is set to 1 ; ; Author ........: Chimp (Gianni Addiego) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _FIFO($vItem = '', $vServiceCall = False) Static Local $oFIFOStack = ObjCreate("Scripting.Dictionary") Static Local $iNDX = 1, $KEYWORD_DEFAULT = 1, $KEYWORD_NULL = 2, $KEYWORD_True = 3 Local $vPull = '' If $vServiceCall Or IsKeyword($vServiceCall) Then ; check second parameter Local $iService = IsKeyword($vServiceCall) ? IsKeyword($vServiceCall) : $vServiceCall ; Default = 1, Null = 2 If String($vServiceCall) = "True" Then $iService = $KEYWORD_True Switch $iService Case $KEYWORD_DEFAULT ; 1 or 'Default' Keyword was passed ; we use the Default Keyword to "normalize" all keys index starting from 1 If $oFIFOStack.Count Then Local $aKeys = $oFIFOStack.keys For $i = 0 To UBound($aKeys) - 1 $oFIFOStack.key($aKeys[$i]) = $i + 1 Next $iNDX = 1 EndIf Return SetExtended($oFIFOStack.Count) Case $KEYWORD_NULL ; 2 or 'Null' Keyword was passed WARNING: the stack is being emptied ; we use the Null KeyWord or value 2 to remove all items from the stack $oFIFOStack.RemoveAll Return SetExtended($oFIFOStack.Count) Case $KEYWORD_True ; 3 or 'True' Keyword was passed just return items count Return SetExtended($oFIFOStack.Count, $oFIFOStack.Count) Case Else ; Return SetError(0, $oFIFOStack.Count, $oFIFOStack.Count) Return SetError(1, $oFIFOStack.Count) EndSwitch EndIf If $vItem = '' Then ; no Item to stack, just pull from stack then If $oFIFOStack.Count Then ; ensure stack is not empty $vPull = $oFIFOStack.Item($iNDX) ; get the first item still in stack $oFIFOStack.Remove($iNDX) ; remove item from stack $iNDX += 1 ; raise the bottom index Return SetError(0, $oFIFOStack.Count, $vPull) ; return item to caller Else Return SetError(1, 0, '') EndIf Else $oFIFOStack.ADD($oFIFOStack.Count + $iNDX, $vItem) ; Add item SetExtended($oFIFOStack.Count) EndIf EndFunc ;==>_FIFO ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LIFO ; Description ...: A simple implementation of a LIFO stack (can be used to pull or push data from/to the stack) ; ; Syntax ........: _LIFO([$vItem = ''[, $vServiceCall = False]]) ; Parameters ....: $vItem - [optional] A variant value. Default is ''. ; this parameter can be empty or filled with data and behaves like: ; - if empty: the function pulls and return data from the stack ; - if filled: the function push that data to te stack ; $vServiceCall - [optional] A KeyWord or a value. Default is False. ; this parameter allows to perform some internal "methods" ; Note: When this parameter is used the previous parameter $vItem is simply ignored. ; 'Null' or 2 : Remove all items from the stack ; 'True' or 3 : Return the number of elements stored in the stack (returns 0 if stack is empty) ; When this parameter is used the previous parameter $vItem is simply ignored. ; ; Return values .: - when the function is used to Push data: ; returns nothing ; set @extended with the new total number of elements in the stack ; - when the function is used to Pull data: ; returns the pulled data (and removes it from the stack) ; set @extended with the number of elements still in the stack. ; If you try to pull data from an empty stack you get an empty string and @error is set to 1 ; ; Author ........: Chimp (Gianni Addiego) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _LIFO($vItem = '', $vServiceCall = False) Static Local $oLIFOStack = ObjCreate("Scripting.Dictionary") Static Local $KEYWORD_DEFAULT = 1, $KEYWORD_NULL = 2, $KEYWORD_True = 3 Local $vPull = '' ; check if second parameter is used If $vServiceCall Or IsKeyword($vServiceCall) Then Local $iService = IsKeyword($vServiceCall) ? IsKeyword($vServiceCall) : $vServiceCall ; Default = 1, Null = 2 If String($vServiceCall) = "True" Then $iService = $KEYWORD_True ; True = 3 Switch $iService Case $KEYWORD_DEFAULT ; 1 or 'Default' Keyword was passed Return SetExtended($oLIFOStack.Count) Case $KEYWORD_NULL ; 2 or 'Null' Keyword was passed WARNING: the stack is being emptied ; we use the Null KeyWord or value 2 to remove all items from the stack $oLIFOStack.RemoveAll Return SetExtended($oLIFOStack.Count) Case $KEYWORD_True ; 3 or 'True' Keyword was passed just return items count Return SetExtended($oLIFOStack.Count, $oLIFOStack.Count) Case Else ; Return SetError(0, $oFIFOStack.Count, $oFIFOStack.Count) Return SetError(1, $oLIFOStack.Count) EndSwitch EndIf If $vItem = '' Then ; no Item to stack, just pull from stack then If $oLIFOStack.Count Then ; ensure stack is not empty $vPull = $oLIFOStack.Item($oLIFOStack.Count) ; get the top item $oLIFOStack.Remove($oLIFOStack.Count) ; remove item from stack Return SetError(0, $oLIFOStack.Count, $vPull) ; return item to caller Else Return SetError(1, 0, '') EndIf Else $oLIFOStack.ADD($oLIFOStack.Count + 1, $vItem) ; Add item SetExtended($oLIFOStack.Count) EndIf EndFunc ;==>_LIFO  
    • By stafe
      Hello
      I am trying to get chrome to save it's current webpage to a pdf using autoit.  I wold like to save the file into a folder on the desktop called "ChromeFiles" .  However when I use the send command chrome only occasionally responds.
      Thank you
      Simon
       
    • By iamtech
      When I click on print button (Javascript Button) in webpage using _IEAction($btnprint,"click") then display print dialog, like this one:
      i want to Automate this print dialog box and print file using default printer. (not using controlclick).
      its possible to print without showing print dialog box?

    • By natedog102
      Hi everyone. I want to format the output of _INetGetSource to look nice and pretty. 
      Example google.com source output: 
      <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script>(function(){window.google={kEI:'DJtTWvCOI6WGjwSE9JrICg',kEXPI:'18167,1354277,1354916,1355218,1355675,1355793,1356171,1356806,1357219,1357326,3700304,3700519,3700521,4003510,4029815,4031109,4043492,4045841,4048347,4081038,4081164,4095909,4096834,4097153,4097195,4097922,4097929,4098733,4098740,4098752,4102237,4102827,4103475,4103845,4106084,4107914,4109316,4109490,4112770,4113217,4115697,4116349,4116724,4116731,4116926,4116927,4116935,4117980,4118798,4119032,4119034,4119036,4120285,4120286,4120660,4121175,4121518,4122511,4123830,4123850,4124091,4124850,4125837,4126202,4126754,4126869,4127262,4127418,4127473,4127744,4127863,4128586,4128622,4129001,4129520,4129556,4129633,4130362,4130783,4131247,4131834,4132956,4133114,4133509,4135025,4135088,4135249,4135934,4136073,4136092,4136137,4137597,4137646,4140792,4140849,4141281,4141707,4141915,4142071,4142328,4142420,4142443,4142503,4142678,4142729,4142829,4142834,4142847,4143278,4143527,4143902,4144442,4144550,4144704,4145074,4145075,4145082,4145088,4145461,4145485,4145622,4145688,4145713,4145836,4146146,4146183,4146874,4147032,4147043,4147096,4147443,4147800,4147951,4148257,4148304,4148436,4148498,4148573,6512220,10200083,10202524,10202562,15807763,19000288,19000423,19000427,19001999,19002287,19002288,19002366,19002548,19002880,19003321,19003323,19003325,19003326,19003328,19003329,19003330,19003407,19003408,19003409,19004309,19004516,19004517,19004518,19004519,19004520,19004521,19004531,19004656,19004668,19004670,19004692,41317155',authuser:0,kscs:'c9c918f0_DJtTWvCOI6WGjwSE9JrICg',u:'c9c918f0',kGL:'US'};google.kHL='en';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};google.ml=function(){return null};google.wl=function(a,b){try{google.ml(Error(a),!1,b)}catch(d){}};google.time=function(){return(new Date).getTime()};google.log=function(a,b,d,c,g){if(a=google.logUrl(a,b,d,c,g)){b=new Image;var e=google.lc,f=google.li;e[f]=b;b.onerror=b.onload=b.onabort=function(){delete e[f]};google.vel&&google.vel.lu&&google.vel.lu(a);b.src=a;google.li=f+1}};google.logUrl=function(a,b,d,c,g){var e="",f=google.ls||"";d||-1!=b.search("&ei=")||(e="&ei="+google.getEI(c),-1==b.search("&lei=")&&(c=google.getLEI(c))&&(e+="&lei="+c));c="";!d&&google.cshid&&-1==b.search("&cshid=")&&(c="&cshid="+google.cshid);a=d||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+b+e+f+"&zx="+google.time()+c;/^http:/i.test(a)&&google.https()&&(google.ml(Error("a"),!1,{src:a,glmm:1}),a="");return a};}).call(this);(function(){google.y={};google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};}).call(this);google.f={};var a=window.location,b=a.href.indexOf("#");if(0<=b){var c=a.href.substring(b+1);/(^|&)q=/.test(c)&&-1==c.indexOf("#")&&a.replace("/search?"+c.replace(/(^|&)fp=[^&]*/g,"")+"&cad=h")};</script><style>#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important} But I want it outputted like this:
      <!doctype html> <html itemscope="" itemtype="http://schema.org/WebPage" lang="en"> <head> <meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"> <meta content="noodp" name="robots"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"> <title>Google</title> <script> (function() { window.google = { kEI: 'DJtsdfgWGjwSE9JrICg', kEXPI: '18167,1354277,1354916,1355218,1355675,1355793,1356171,1356806,1357219,1357326,37sdfg0304,3700519,3700521,4003510,4029815,4031109,4043492,4045841,4048347,4081038,4081164,4095909,4096834,4097153,4097195,4097922,4097929,4098733,4098740,4098752,4102237,4102827,4103475,4103845,4106084,4107914,4109316,4109490,4112770,4113217,4115697,4116349,4116724,4116731,4116926,4116927,4116935,4117980,4118798,4119032,4119034,4119036,4120285,4120286,4120660,4121175,4121518,4122511,4123830,4123850,4124091,4124850,4125837,4126202,4126754,4126869,4127262,4127418,4127473,4127744,4127863,4128586,4128622,4129001,4129520,4129556,4129633,4130362,4130783,4131247,4131834,413sdfg56,4133114,4133509,4135025,4135088,4135249,4135934,4136073,4136092,4136137,4137597,4137646,4140792,4140849,4141281,4141707,4141915,4142071,4142328,4142420,4142443,4142503,4142678,4142729,4142829,4142834,4142847,4143278,4143527,4143902,4144442,4144550,4144704,4145074,4145075,4145082,4145088,4145461,4145485,4145622,4145688,4145713,4145836,4146146,4146183,4146874,4147032,4147043,4147096,4147443,4147800,4147951,4148257,4148304,4148436,4148498,4148573,6512220,10200083,10202524,10202562,15807763,19000288,190sdfg23,19000427,19001999,19002287,19002288,19002366,19002548,19002880,19003321,19003323,19003325,19003326,19003328,19003329,19003330,19003407,19003408,19003409,19004309,19004516,19004517,19004518,19004519,19004520,19004521,19004531,19004656,19004668,19004670,19004692,41317155', authuser: 0, kscs: 'c9c918f0_DJtTWvCOI6WGjwSE9JrICg', u: 'c9c918f0', kGL: 'US' }; google.kHL = 'en'; })(); ....... I checked the forums and did not see any UDFs that allow for this. I see the Chilkat UDF but that only supports JSON. Any help would be greatly appreciated.
×
×
  • Create New...