How can I monitor print jobs for a printer?

Posted on 2008-11-20
Last Modified: 2012-05-05
I am currently researching to develop an application that that monitors print jobs queueing to a particular printer, coming from various workstations, each having a different user.  I need to monitor the userid of every user sending print jobs to the printer as well as the number of pages being sent.

Any help with pointing me at the right direction for a good start is appreciated.

Question by:b0rnslipy
    LVL 1

    Expert Comment

    well printer usually have a good support for snmp, so I think you have to work in that direction.
    have a look at this post
    LVL 6

    Expert Comment

    I would recommend to go down another path and use WMI to subscribe to events, then you will get information about printjobs including UserID, document name, pages printed, total pages, size etc. I am developing an application like that as well that can be running remotely.
    You should use something called System.Management.ManagementEventWatcher where you define a query that will subscribe to any event regarding a printjob Create, Modify, delete. A query could look like this
    SELECT * FROM __InstanceOperationEvent WITHIN 0.5 WHERE TargetInstance ISA "Win32_PrintJob"
    There are different things you can subscribe to and whats interesting to use here is
    __InstanceCreateEvent  (When a printjob is created)
    __InstanceModifiedEvent (When a printjob changes)
    __InstanceDeletionEvent (When a printjob is deleted/removed)
    __InstanceOperationEvent (includes all three above and you have to look what type it is)
    These WMI queries can be used to get event triggers for at least all Win32_ classes in CimV2, that includes, Processes, printers etc.

    Look at these webpages for more info about the WMI usage
    __InstanceCreateEvent (Microsoft MSDN)
    __InstanceModifiedEvent (Microsoft MSDN)

    __InstanceDeletionEvent (Microsoft MSDN)
    __InstanceOperationEvent (Microsoft MSDN)

    WMI Classes (Win32)
    System.Management.ManagementEventWatcher (Microsoft MSDN)
    Below is a code snippet of how to use the ManagementEventWatcher, it is just an excerpt from my code so its not complete, but I hope you get a point of how to use it.
    Good luck!
    / Mikael

    // Declaration
    mWatcher = new ManagementEventWatcher(); 
    mWatcher.Scope = new ManagementScope("\\\\" + strComputerName + "\\root\\CIMV2"); 
    // you can play around with the WITHIN interval but it costs performance if using faster intervals
    string oQuery = "SELECT * FROM __InstanceOperationEvent WITHIN 0.1 WHERE TargetInstance ISA \"Win32_PrintJob\""; 
    mWatcher.Query = new EventQuery(oQuery); 
    mWatcher.EventArrived += new EventArrivedEventHandler(mWatcher_EventArrived); 
    mWatcher.Stopped += new StoppedEventHandler(mWatcher_Stopped); 

    Open in new window

    LVL 6

    Accepted Solution

    Forgot to tell that the computername in this case is the printserver where the printqueues are installed (not the clients printing)
    / Mikael
    LVL 6

    Expert Comment

    The solution I have suggested (last post before admin post) provides exacly the functionality that the author asked for,  also provided a code example, so its a sad that the the effort taken is left  unnoticed.
    / Mikael

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now