C. drawing. in the namespace of printing, some access to system printers is provided. However, to be honest, it is too weak to obtain printer-related attributes.
C # obtain the detailed information of the printer. Two methods are commonly used:
- Use Windows APIs
- Use WMI
Here I am Using WMI, because this method uses SQL-like methods to manage Windows WMI information as a database form, easy to use
In. net, WMI usage is stored in the space of system. management. To Use WMI, you must first addSystem. Management. dllReference
DetailsCodeAs follows:
StringWmisql ="Select * From win32_printer";ManagementobjectcollectionPrinters =NewManagementobjectsearcher(Wmisql). Get ();Foreach(ManagementobjectPrinterInPrinters ){Propertydatacollection.PropertydataenumeratorPVDF = printer. properties. getenumerator ();While(Partial. movenext ()){MessageBox. Show (PVDF. Current. Name +":"+ PVDF. Current. value );// Display the attribute name in the form of the attribute value}}
It should be clear at a glance, hey