我正在尝试在共享打印机上打印文档;我需要获取打印队列详细信息。以下代码始终从“Microsoft XPS 文档”获取队列,因为作业数 = 0。但是我的默认打印机配置为“HP LaserJet P1505n”
LocalPrintServer server = new LocalPrintServer()
PrintQueueCollection queueCollection = server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
Logger.LogInfo("PrintQueue1", "Printer1 Queue Name " + pq.FullName);
printQueue = pq;
numberOfJobs = printQueue.NumberOfJobs;
Logger.LogInfo("numberOfJobs1"+ numberOfJobs);
}
如何从特定共享打印机获取打印队列详细信息?我也试过关注
PrintServer server = new PrintServer(@"\\192.168.100.168\HP LaserJet P1505n");
但出现错误:
Win32 error: The filename, directory name, or volume label syntax is incorrect
我在这里错过了什么?
最佳答案
How to get print queue details from that specific shared printer?
尝试这样的事情:
// string.Empty or null for local printers
string printServerName = @"\\server";
string printQueueName= "printer";
PrintServer ps = string.IsNullOrEmpty(printServerName)
// for local printers
? new PrintServer()
// for shared printers
: new PrintServer(printServerName);
PrintQueue pq = ps.GetPrintQueue(printQueueName);
Console.WriteLine(pq.FullName);
Console.WriteLine(pq.NumberOfJobs);
// output is printer uri (\\server\printer) and 0.
也可以使用服务器 ip 地址(如字符串)代替服务器名称。
string printServerName = @"\\192.168.1.111"; // for example
即
用于本地打印机 PDFCreator 集
string printServerName = null;
string printerName = "PDFCreator";
对于服务器S集合上的共享打印机P
string printServerName = @"\\S";
string printerName = "P";
关于c# - 获取共享打印机的打印队列详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20279690/