Reputation: 587
Using C# - I'm trying to find a list of all printers that are local and online (i.e. connected and ready to accept print requests)
I know the printer driver works - jobs will just wait until the printer is back online, but I need to find those specific that are online. These are clearly available to windows but the .net framework doesn't seem to accurately expose those which are currently online.
I'm trying to use lots of different methods and none seem to accurately work
// Get a list of available printers.
var printServer = new PrintServer();
var printQueues = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
foreach (PrintQueue printQueue in printQueues)
{
Console.WriteLine(printQueue.IsOffline); // This works for IsOffline, but doesn't tell us those that are online - and it's not an inverse relationship
}
very frustrating - any help appreciated.
Should add I'm using windows 8.1, and the solution should work also with win 7+
Edit:
So given the following collection of printers :
I would expect to see something along the lines of
Getting all Printers
Send To OneNote 2013 : Online
Pack1 : Offine
Microsoft XPS Document Writer : Online
Fax : Online
EPSONB12B28 (XP-412 413 415 Series) : Offine
Brother MFC-9970CDW Printer : Online
But they are ALWAYS reported as Online on any status I see
Upvotes: 2
Views: 3231
Reputation: 398
I have queried just about every conceivable windows device either by native driver or using Windows Management Instrumentation (WMI) classes.
To get you started, take a read of this article with C# source: http://www.codeproject.com/Articles/80680/Managing-Printers-Programatically-using-C-and-WMI
Also, not in C# but VB, some quick glance info on the same subject here: http://msdn.microsoft.com/en-us/library/aa394598(v=vs.85).aspx
Full WMI reference here: http://msdn.microsoft.com/en-us/library/aa394572(v=VS.85).aspx
Cheers and good luck!
Upvotes: 1