Printing event on C#
How can I keep track of Printer's activities such as:
- When did printing start?
- Ho开发者_如何学运维w many pages have been printed out? etc
You would want to set up a service that listens to printer change notification events using the FindFirstPrinterChangeNotification, FindNextPrinterChangeNotification, and FindClosePrinterChangeNotification functions. And listen to the PRINTER_CHANGE_JOB event. When a print job event is raised you can get access to the necessary job information from the PRINTER_NOTIFY_INFO_DATA structure.
This method should be taken with a grain of salt. I have found from experience that printer events are unreliable when the server is under load with many print jobs occurring at the same time. Some printer events will not fire.
Obviously this solution will take a whole lot of P-Invoking & Marshalling, so I wish you luck. If writing the application in C++ is an option it would probably be easier than in C# in this case.
explaining it here is so boring. I suggest you read the full article http://support.microsoft.com/kb/160129
I guess you could use WMI.
Here is a blog-entry regarding getting printer-info using WMI: http://aleemkhan.wordpress.com/2005/09/20/getting-printer-information-through-wmi/
Here is some code on getting printer events (in VB.Net though): http://social.technet.microsoft.com/Forums/en/ITCG/thread/71258e18-5516-4a90-be76-5b83855b2841
Perhaps use the Spooler API to get going? I've not used this before, but I recon it'll involve a fair amount of P/Invoke.
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/a7160b44-0984-48c4-afef-b9a6ee4a8483
精彩评论