【问题标题】:How do I use LocalPrintServer to target a specific printer?如何使用 LocalPrintServer 来定位特定的打印机?
【发布时间】:2011-04-13 07:37:54
【问题描述】:

以下问题:How do I retrieve a list or number of jobs from a printer queue?

我仍然不知道如何使用 LocalPrintServer 类来定位我目前只知道名称的特定打印机。该应用程序应该一次打印到多台机器上,并且需要单独监控所有打印后台处理程序。谁能提供一个代码 sn-p 来说明我如何仅使用打印机名称来实例化 LocalPrintServer 对象?

提前致谢!

编辑:添加解决方案的代码片段:

private int GetNumberOfPrintJobs()
{
    LocalPrintServer server = new LocalPrintServer();
    PrintQueueCollection queueCollection = server.GetPrintQueues();
    PrintQueue printQueue = null;

    foreach (PrintQueue pq in queueCollection)
    {
        if (pq.FullName == PrinterName) //PrinterName is a classmember
            printQueue = pq;
    }

    int numberOfJobs = 0;
    if (printQueue != null)
        numberOfJobs = printQueue.NumberOfJobs;

    return numberOfJobs;
}

毕竟这并不难!

【问题讨论】:

    标签: c# printing queue


    【解决方案1】:

    重要提示GetPrintQueues 不会从用户的角度返回所有已安装的打印机 - 只是那些归本地服务器“拥有”的打印机。

    更奇怪的是,LocalPrintServer.DefaultPrintQueue 不一定包含在 GetPrintQueues() 中,即使它来自 LocalPrintServer 对象。

    如果您使用System.Drawing.Printing.PrinterSettings.InstalledPrinters(即string[]),您将从用户的角度获得所有已安装打印机的列表。

    如果您已安装远程打印机(在打印服务器上),其中一些可能位于远程计算机上。如果它是可通过 IP 访问的联网打印机,那么它仍然是本地打印机:

    "Send To OneNote 2010"  
    "Microsoft XPS Document Writer" 
    "HP LaserJet P2050 Series PCL6" 
    "HP LaserJet 1020"  
    "Fax"   
    "\\\\ike\\LUCY" 
    "\\\\shipping\\HP LaserJet 1020"    
    

    要在远程服务器上检索打印队列,您需要执行以下操作:

    new PrintServer("\\ike").GetPrintQueue("LUCY")
    

    是的,您需要自己解析它。

    【讨论】:

    【解决方案2】:

    尝试使用 LocalPrintServer.GetPrintQueue 指定打印机名称。

    【讨论】:

    • 这实际上是我想尝试的。我去看看!
    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多