emirate
emirate

Reputation: 159

Printing event on C#

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

Upvotes: 1

Views: 5630

Answers (4)

BBoy
BBoy

Reputation: 1113

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.

Upvotes: 2

S.C. Madsen
S.C. Madsen

Reputation: 5256

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

Upvotes: 1

user415789
user415789

Reputation:

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

Upvotes: 1

Tom
Tom

Reputation: 3374

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

Upvotes: 0

Related Questions