How can I monitor print jobs for a printer?

b0rnslipy
b0rnslipy used Ask the Experts™
on
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.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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
http://blog.crowe.co.nz/archive/2005/08/08/182.aspx
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)
http://msdn.microsoft.com/en-us/library/aa394649(VS.85).aspx
 
__InstanceModifiedEvent (Microsoft MSDN)
http://msdn.microsoft.com/en-us/library/aa394651(VS.85).aspx

__InstanceDeletionEvent (Microsoft MSDN)
http://msdn.microsoft.com/en-us/library/aa394650(VS.85).aspx
__InstanceOperationEvent (Microsoft MSDN)
http://msdn.microsoft.com/en-us/library/aa394652(VS.85).aspx

WMI Classes (Win32)
http://msdn.microsoft.com/en-us/library/aa394084(VS.85).aspx
System.Management.ManagementEventWatcher (Microsoft MSDN)
http://msdn.microsoft.com/en-us/library/system.management.managementeventwatcher(VS.80).aspx
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

Forgot to tell that the computername in this case is the printserver where the printqueues are installed (not the clients printing)
/ Mikael
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.
br
/ Mikael
 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial