Printing event on C#

杀马特。学长 韩版系。学妹 提交于 2019-12-25 11:56:25

问题


How can I keep track of Printer's activities such as:

  • When did printing start?
  • How many pages have been printed out? etc

回答1:


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.




回答2:


explaining it here is so boring. I suggest you read the full article http://support.microsoft.com/kb/160129




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/4276269/printing-event-on-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!