Sagar
Sagar

Reputation: 429

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. 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. Any help will be appreciated. Thanks in advance.

Upvotes: 4

Views: 10440

Answers (1)

Sagar
Sagar

Reputation: 429

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. This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.

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.

Upvotes: 5

Related Questions