In a LAN normally printers are shared, and we can add these shared computers in the LAN to our machine through Windows “Add Remote Printer”. I want to get the list of added printer like this, and there online status and printer settings through C#. The list of added printers could be obtained by
System.Drawing.Printing.PrinterSettings.InstalledPrinters
through this code I can get the list of added printers to a combobox. The problem is how can I get the online status of each printer, and there other possible settings through the c# code. Please help.
As an alternative to WMI, you can use the Print Spooler API to gather detailed information about the printers. Most of the P/Invoke signatures for the API are available on http://www.pinvoke.net.
Open a handle to a printer:
http://www.pinvoke.net/default.aspx/winspool.OpenPrinter
Gather printer information:
http://www.pinvoke.net/default.aspx/winspool.GetPrinterData
Edit:
Quickly smashed together an example of what you can gather from the PrintSpoolerApi as per request.
PrintSpoolerAPIExample:
Create new console project and replace all code in Program.cs with this (.NET 3.5 and above, due to type inference), the printer details of each printer available on the machine (local or networked) will be printed to the console. The status value is what you are interested in. The status code for “Ready” is 0, mess around by disabling printers and disabling your network connection to networked printers to see the status change.
You can retrieve even more details from the API, if required.