c# - 获取共享打印机的打印队列详细信息

标签 c# .net printing system.printing printqueue

我正在尝试在共享打印机上打印文档;我需要获取打印队列详细信息。以下代码始终从“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/

相关文章:

c# - 使用 http 触发的函数将输入绑定(bind)到表存储

c# - 如何写入自定义事件日志?

java - 如何防止 Xtend 模板在循环期间打印变量

python - 如何在输出中不显示括号和 ""的情况下打印列表? python 3.3.2

java - 使用 USB 电缆打印问题

c# - 我应该使用 ToString() 还是 GetDateTimeFormats() 来格式化 DateTime?

c# - 具有在 C# 中可见的算术运算符的 F# 结构

c# - Wcf 服务异常良好实践

c# - WinForms,在文本后设置输入光标。在文本末尾替换

.net - 使用动态 OrderBy 进行分页/分页的 Linq 表达式