Printing event on C#

前端 未结 4 696
萌比男神i
萌比男神i 2021-01-25 17:26

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

  • When did printing start?
  • How many pages have been printed out? etc
相关标签:
4条回答
  • 2021-01-25 17:44

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

    0 讨论(0)
  • 2021-01-25 17:53

    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

    0 讨论(0)
  • 2021-01-25 17:55

    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.

    0 讨论(0)
  • 2021-01-25 18:04

    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

    0 讨论(0)
提交回复
热议问题