为什么在Windows中找到打印机状态如此困难?

时间:2014-06-18 15:48:01

标签: c# .net wpf windows printing

使用C# - 我试图找到所有本地和在线打印机的列表(即连接并准备好接受打印请求)

我知道打印机驱动程序有效 - 作业将等到打印机重新联机,但我需要找到那些在线的特定打印机。这些显然适用于Windows,但.net框架似乎无法准确地揭示当前在线的那些。

我试图使用许多不同的方法,似乎没有一个准确的工作

// 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  
}

非常令人沮丧 - 任何帮助表示赞赏。

应该使用Windows 8.1添加我,并且解决方案也应该与win 7 +

一起使用

编辑:

因此给出了以下打印机集合:

List of Printers - some offline

我希望看到

的内容
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

但在我看到的任何状态下,他们总是被报告为在线

1 个答案:

答案 0 :(得分:1)

我已经通过本机驱动程序或使用Windows Management Instrumentation(WMI)类查询了所有可能的Windows设备。

为了帮助您入门,请使用C#source:http://www.codeproject.com/Articles/80680/Managing-Printers-Programatically-using-C-and-WMI

阅读本文

此外,不是在C#而是在VB中,这里有一些关于同一主题的快速浏览信息:http://msdn.microsoft.com/en-us/library/aa394598(v=vs.85).aspx

此处的完整WMI参考:http://msdn.microsoft.com/en-us/library/aa394572(v=VS.85).aspx

干杯,祝你好运!