0

I'm trying to make a batch file that will be used to add network printers to computers at my work. The batch file will be run locally by an IT assistant on the computer that needs the printer added. The computers are running Windows 10.

We have two print servers, and a printer name that is specified might be on either print server. The aim is to simply try to add the printer from both servers. The correct one will succeed, the incorrect one will fail.

I'm using rundll32 printui.dll,PrintUIEntry for this. A snippet of my code is below.

rundll32 printui.dll,PrintUIEntry /in /n\\PRINTSERVER1\%printername% /q
rundll32 printui.dll,PrintUIEntry /in /n\\PRINTSERVER2\%printername% /q

From what I can tell, the /q switch should suppress error messages, such as this one:

Windows couldn't connect to the printer

However, I still see the error message show up when the script is run. Does anyone know how to suppress this warning?

2
  • You can simply add IF EXIST \\PRINTSERVER<#>\%printername% to the beginning of each line where the print server will be the respective printserver name for each line so it will only add the printer if it is accessible. So IF EXIST \\PRINTSERVER2\%printername% rundll32 printui.dll,PrintUIEntry /in /n\\PRINTSERVER2\%printername% /q. Otherwise please help us understand how one could be incorrect and the other not on any of the machines this is run against. I assume printserver will only be accessible from certain PCs on specific subnets for example, etc. Feb 8, 2018 at 13:26
  • Thanks for the info on using IF EXIST; I didn't know that would work for printers. The aim was to add arbitrary printers, which could be on either print server. However, modifying the script to remove the ability to add arbitrary printers ended up being the best solution. The assistants can simply add printers manually if they have a special case.
    – Zman9600
    Feb 10, 2018 at 5:18

0

You must log in to answer this question.