SNMP for Local printer?

I think SNMP is the correct approach. Most printers implement the standard printer MIB and the RFC 1213 MIB so any property you can get from there is going to be model independent. For instance, if you look for the serial number your property is probably prtGeneralSerialNumber 1.3.6.1.2.1.43.5.1.1.17

For other properties you are going to need to search in the specific MIBs, for instance in the HP Laserjet MIB you have a lot of stuff like printed-media-usage, printed-media-simplex-count, printed-media-duplex-count, usage-average-toner-coverage, scanned-media-usage, total-color-page-count.....

To use SNMP the most extended library is Net-SNMP but it uses a C API and I don't recommend it if you need to use it in heavy multithreaded applications or using SNMPv3. There are other libraries like link text that look very promising, but most of the reliable libraries out there commercial and not very cheap.

All the above is quite easy to implement if the printer is network connected, now if the printer is USB or PPI connected you need to get your hands into the HP SNMP Proxy Agent, you can find a great post here. It says that basically it is a little Windows software that piggy-backs on the standard Windows SNMP service and provides SNMP data on the default HP printer connected to a computer via USB or parallel cable. I don't know if it works with any other brands but it looks like it uses the standard protocol DOT4 over USB to emulate typical TCP/IP communications. If there is any standard method to connect to all those printers this one is the most promising. Another method that I can think of is to hack the individual drivers of each model to see if they provide such information (which most certainly do) and make the respective calls to them to get it, but on this task I think that you are on your own.

EDIT

With driver hacking I mean reverse engineering probably the tools of each driver. For example, if a printer has a utility that shows the toner status try to understand how it works, I would start using Depends to open the executable and see which dlls it is using and what methods they publish, if you find a method like GetTonerStatus in the dll it is worth to try to use it.

alt text
(source: dependencywalker.com)

If the tool is written in .Net it much easier because yo can have access to the source code by decompiling it (I don't know about legal issues of this method). Use reflector to do it and you will see it clearly.

alt text
(source: corypeters.net)

There is a great book that covers this aspects called Reversing: Secrets of Reverse Engineering

As said before this is a long path but probably the only one to achieve what you want to do, you might want to reconsider the viability of project after investigating a bit the topics I mentioned.


You can get out quite a bit of information about printers via WMI, though I'm not sure if it contains the information you're looking for:
http://msdn.microsoft.com/en-us/library/Aa394363

I think HP printers store their Serial-numbers somewhere under this registry key (possibly a key called identity or similar):
HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard\

I've never used SNMP, though I remembered this library that might be of use if you go down that route:
http://www.codeproject.com/KB/cs/SNMPDLL.aspx

Tags:

C#

Vb.Net

Snmp