【问题标题】:printserver throwing "Win32 error: The printer name is invalid." exception despite the server path provided is correct打印服务器抛出“Win32 错误:打印机名称无效。”尽管提供的服务器路径是正确的,但异常
【发布时间】:2013-10-25 08:47:49
【问题描述】:

我不知道为什么这不起作用:

PrintServer printServer = new PrintServer("\\\\servername");

我遇到了 PrintServer 初始化问题。即使提供的打印机服务器路径是有效路径,上述异常也会继续出现。之所以这么说,是因为我能够使用printerServer.GetPrintQueues 枚举所有打印机并foreach printQueue 以获取相应的HostingPrintServer 名称。

EnumeratedPrintQueueTypes[] queueTypesArray = new EnumeratedPrintQueueTypes[] 
{
    EnumeratedPrintQueueTypes.Connections,
    EnumeratedPrintQueueTypes.Local,
};
PrintQueueIndexedProperty[] indexPropertyArray = new PrintQueueIndexedProperty[]
{
    PrintQueueIndexedProperty.Name
};

PrintServer printServer = new PrintServer();
PrintQueueCollection queueCollection = printServer.GetPrintQueues(indexPropertyArray, queueTypesArray);

foreach (PrintQueue pq in queueCollection)
{
    if (pq.FullName == printerName)
    {
        this.printServerName = pq.HostingPrintServer.Name;
        this.printerName = pq.Name;
    }
}

我也尝试过使用这篇文章建议的方式来获取 DNS hostEntry,但没有任何运气。

PrintServerException - "...name is invalid" even though I can access the path from windows

供您参考,我正在使用在 Windows XP 上运行的 Visual Studio 2010,并连接了两台网络打印机。打印机可以使用 PrintDocument 毫无问题地执行打印,并且打印机也会显示在 PrintDialog 上。

以前有人遇到过这个问题吗?如果是,请问您是如何解决问题的?

提前致谢。

编辑:

刚刚用另一台“真正的”服务器打印机进行了测试,上述方法工作正常。据信,我不确定它的行为是如何导致问题的 Novell iPrint 服务。如果有人知道更多关于使用 C# 访问 Novell iPrint 打印服务器的方法,请随时分享。我目前仍在寻找 解决方案。

【问题讨论】:

    标签: c# winforms novell system.printing


    【解决方案1】:

    嘿,我遇到了类似的问题,这是我观察到的并进行了以下更改,请尝试让我知道。

    由于系统上缺少 Windows 功能/角色“打印和文档服务”而出现此问题。管理多台打印机或打印服务器以及将打印机迁移到其他 Windows 服务器或从其他 Windows 服务器迁移时需要此角色。

    要添加角色转到控制面板->打开或关闭窗口功能->单击复选框“打印和文档服务”->安装。

    如果您无法添加此规则,请与网络管理员联系以安装此规则。

    添加角色后,您可以创建打印服务器对象并获取相应服务器上的所有打印队列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多