[英]Exception occurred while creating the PrintServer object. Win32 error: The printer name is invalid
Hi, I'm getting this exception when I try to create printserver
object. 嗨,当我尝试创建
printserver
对象时遇到了这个异常。 Here is my code: 这是我的代码:
PrintServer printServer = new PrintServer(@"\\" + printServerName);
PrintQueue printQueue = printServer.GetPrintQueue(printerName);
I'm trying to get the printers from another machine which is running on Windows Server 2012. Same code works fine if I try to access some OS based system. 我正在尝试从运行Windows Server 2012的另一台计算机上获取打印机。如果尝试访问某些基于OS的系统,则相同的代码可以正常工作。 Any help will be appreciated.
任何帮助将不胜感激。 Thanks in advance.
提前致谢。
I found the answer for this, and i know many others are also looking for this issue. 我找到了答案,并且我知道许多其他人也在寻找这个问题。
This issue was occuring due to windows feature/role "Print and Document service" is missing on the system. 由于Windows功能/角色“系统没有打印和文档服务”,因此出现了此问题。 This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.
管理多个打印机或打印服务器以及将打印机迁移到其他Windows服务器或从其他Windows服务器迁移时,需要此角色。
To add the role Go To Control Panel->Turn windows feature on or off->click on check box "Print and Document Service"->install. 要添加角色,请转到“控制面板”->“打开或关闭窗口功能”->单击复选框“打印和文档服务”->“安装”。
See with network administrator for installing this rule if you unable to add it. 如果无法添加此规则,请与网络管理员联系以安装此规则。
After adding the role you can able to create print server object and get the all the printqueues on respective server. 添加角色后,您可以创建打印服务器对象并获取相应服务器上的所有打印队列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.