使用System.Drawing.Printing获取队列状态 [英] Using System.Drawing.Printing to get Queue Status
问题描述
我一直在尝试使用System.Drawing.Printing;
来获取网络打印机的队列状态.
I've been trying to use System.Drawing.Printing;
in order to get the queue status of a network printer.
我可以检索打印机的属性,但似乎无法真正获得队列状态.
I can retrieve the properties of the printer but I can't really seem to get the queue status.
这是我到目前为止尝试过的:
This is what I've tried so far:
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = "ES5461 MFP(PCL)"; // Load the appropriate printer's setting
从那里我可以看到打印机是有效的,因为ps.IsValid
是true
,但是我不能再继续了.
From there I can see that the Printer is valid since ps.IsValid
is true
but I can't go any further.
我也尝试过使用System.Management
来检索状态,但是我只知道如何转储信息,也没有队列信息.
I've tried as well to use System.Management
to retrieve the status but I just know how to dump the information and there's no queue information as well.
string printerName = "ES5461";
string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}%'", printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection coll = searcher.Get();
foreach (ManagementObject printer in coll)
{
foreach (PropertyData property in printer.Properties)
{
Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
}
}
您知道使用任何.dll检索队列状态(文档数)的任何方法吗?
Do you know of any way to retrieve the queue status (number of documents) using any .dll?
推荐答案
感谢Nissim,我可以解决它:
Thanks to Nissim I could solve it:
var printServer = new PrintServer();
var myPrintQueues = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
foreach (PrintQueue pq in myPrintQueues)
{
pq.Refresh();
if (!pq.Name.ToLower().Contains("es5461")) continue;
PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();
foreach (PrintSystemJobInfo job in jobs)
{
var aux = job;
}// end for each print job
}// end for each print queue
正如Nissim所建议的,结合使用PrintServer
(System.Printing
)和PrintQueue
,我实际上可以访问队列信息.
As you can see using the PrintServer
(System.Printing
) combined with the PrintQueue
as suggested by Nissim I can actually access to the queue information.
这篇关于使用System.Drawing.Printing获取队列状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!