Sign in to follow this  
Followers 0
zeroman

Print statistics

9 posts in this topic

Hi guys,

AutoIt is pretty good for developing self-use program.

I would like to write a program which counts the print job that the computer execute everyday. And the data should be recorded in a text file.

How could I monitor the printer (the only one) for the number of printing per day??

Thank you for your kindly response.

Chris YEUNG

Share this post


Link to post
Share on other sites



Some questions that come to mind:

  • Is it a local attached or network printer
  • What brand/type do you use
  • Is the printer SNMP enabled (so you can use the printers statistics)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Some questions that come to mind:

  • Is it a local attached or network printer
  • What brand/type do you use
  • Is the printer SNMP enabled (so you can use the printers statistics)

1. It is a local printer which doesn't share with other PC

2. It is a thermo receipt printer (EPSON EU-T400)

3. I'm sorry that I don't know what is SNMP. How can I check the SNMP is enabled? If it is enabled, how can I get the statistics information?

Thank you very much

Chris YEUNG

Share this post


Link to post
Share on other sites

Thanks for the additional information. I have no local printer to test, but I think using WMI you could extract some of the needed information.

Could you please download Scriptomatic and hava a look at the Win32_Printer WMI Class (see attachement).

The code generated by Scriptomatic is pure Autoit so you can copy&paste the required parts to your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the additional information. I have no local printer to test, but I think using WMI you could extract some of the needed information.

Could you please download Scriptomatic and hava a look at the Win32_Printer WMI Class (see attachement).

The code generated by Scriptomatic is pure Autoit so you can copy&paste the required parts to your script.

Hi,

there is a missing include in scriptomatic.au3 for AutoIT 3.3.0.0:

#include <WindowsConstants.au3>

@zeroman: What do you mean: And the data should be recorded in a text file.

The data of the print job? or just the name of the printjob e.g. FP00000.SPL

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

Hi,

there is a missing include in scriptomatic.au3 for AutoIT 3.3.0.0:

#include <WindowsConstants.au3>

@zeroman: What do you mean: And the data should be recorded in a text file.

The data of the print job? or just the name of the printjob e.g. FP00000.SPL

;-))

Stefan

To water: Thank you for your quick response, I've run the class but cant find needed information

To 99ojo: Thanks. I just ran the .au3 by declaring some variables without the included. No problem

I just want to show the number of printing(or print job?) per day. And save the numbers into a text file only. Not the information about print jobs.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

To water: Thank you for your quick response, I've run the class but cant find needed information

To 99ojo: Thanks. I just ran the .au3 by declaring some variables without the included. No problem

I just want to show the number of printing(or print job?) per day. And save the numbers into a text file only. Not the information about print jobs.

Hi,

have a look at WMI Class WIN32_PrintJob. You have to test, what is happening with the WMI report

1) A document is printed.

2) Several documets are printed

3) What does the WMI report generate, after the documents were printed and print spool is empty

4) What does the report do, if you print a new document after step 3)

Maybe another solution is, to monitor spool directory for files and compare the file attributes (date, size etc.) and plot an internal counter to a text file.

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I think this should OK. Anyone can test it for me in a local OR network OR multiple printers?

HotKeySet("{ESC}", "_Quit")
$counter = 0
$intPreID = 0

while 1
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PrintJob", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            If $objItem.JobID <> $intPreID Then
                ConsoleWrite("JobId: " & $objItem.JobId & @CRLF)
                $counter = $counter + 1
                MsgBox(1,"",$counter)
                $intPreID = $objItem.JobID
            EndIf
        Next
    EndIf
WEnd



Func _Quit()
    Exit
EndFunc  ;==>_Quit
Edited by zeroman

Share this post


Link to post
Share on other sites

I think this should OK. Anyone can test it for me in a local OR network OR multiple printers?

HotKeySet("{ESC}", "_Quit")
$counter = 0
$intPreID = 0

while 1
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PrintJob", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            If $objItem.JobID <> $intPreID Then
                ConsoleWrite("JobId: " & $objItem.JobId & @CRLF)
                $counter = $counter + 1
                MsgBox(1,"",$counter)
                $intPreID = $objItem.JobID
            EndIf
        Next
    EndIf
WEnd



Func _Quit()
    Exit
EndFunc  ;==>_Quit

Hi,

for decrease cpu-usage just insert at minimum a sleep (20) before the WEND.

Otherwise you would have CPU usage 100 % all the time.

;-))

Stefan

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  
Followers 0