Adding network printers via .bat script

Hi all,

Can anyone tell me where I'm going wrong with this? I have 2x print servers with multiple printers on each (B/W and Colour respectively) I want anyone mapping a printer to be prompted for the print server and then the printers name.

If I remove the ...\echo %server\echo %printer% and manually modify it for the correct server/printer name details it works fine so I assumed it would just look for the variables instead [Obviously not].

"@echo off
set p/ server=Enter Print Server
set p/ printer=Enter Printer Name
REM Add printer
rundll32 printui.dll,PrintUIEntry /in /n\echo %server%\echo %printer%"

Thanks!

I'm going to assume you're unable to complete this task within group policy?

...Wait. I just re-read that. You're wanting to put a .bat on each individuals desktop, have them click it, then input the share name of the printer? That seems rather convoluted for a typicaly userbase.

Correct, that's unfortunately not an option for a few reasons.

Thanks.

What about a logon script using a simple: start \ \computer\"Printer"

As stated in my edit, the way you're approaching is a bit confusing for your average user. The less input they have the better.

Edit: And I don't mean to critique your approach, I'm just speaking from experience of having to deal with a userbase and coming up with straight forward sounding ideas that go terribly wrong because they can't execute it correctly. It's taught me to take the easiest approach possible at all times.

Shouldn't that be set /p rather set p/?

Also I don't think you need to echo %server% and %printer% in order to get it in line with what you're trying to execute. You may be trying to add a server/printer combo of "echo servername\echo printername"

One thing to do is always check to make sure that the variables are populated with what you expect.

I did this in Powershell a while back for importing a csv list of printers. Maybe it could be useful to you.

$Desktop = [Environment]::GetFolderPath("Desktop")
$printers = import-csv $Desktop\printers.csv

foreach ($printer in $printers) {
    $IP = ($printer.PortName)
    $Driver = $printer.DriverName
    $Name = $printer.Name
    Add-PrinterPort -Name "IP_$IP" -PrinterHostAddress $IP
    Add-Printer -DriverName "$Driver" -Name "$Name" -PortName "IP_$IP"
}

Edit:
Also, I agree, this should be done via group policy or something. But sometimes that's not an option.

Edit Edit:
Ah, actually my script is for adding network printers directly to Windows, with no print server. That may be less than useful. Unless it gets you into Powershell, in which case it's incredibly useful.

OK I do this, this is one of the first few scripts I ever wrote. and am too lazy to clean it up other than remark out old un-needed lines. This runs and installs all the printers in the building, and set color profiles and black and white profles so to the user each printer shows up as 2 1 being color other being B&W

@echo off

rem Deleting old printers
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 3rd Floor - Black and White"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 3rd Floor - Color"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 4th Floor - Black and White"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 4th Floor - Color"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 1st Floor - Black and White"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 1st Floor - Color"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 2nd Floor - Black and White"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon 2nd Floor - Color"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C5250/5255 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C5235/5240 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C2030 (color) UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C2030 (BW) UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C5045 (color) UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Canon iR-ADV C5045 (BW) UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "OCe VL4222 (near Art)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "OCe VL4222 (near Legal)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "OCe VL4222 (near Online)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "OCe VL4222 (near Circ.)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Konica Minolta (near Circ.)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Konica Minolta (near Legal)"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "KONICA MINOLTA 423SeriesPCL"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "KONICA MINOLTA 554eSeriesPCL"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Konica Minolta (near Adver.)"

rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x
rem Deleting ports first.
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.14"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.16"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.18"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.20"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.21"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.22"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "10.2.8.23"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.14"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.16"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.18"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.20"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.21"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.22"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.8.23"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.15"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.16"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.17"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.18"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.19"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.21"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "IP_10.2.10.23"

rem Deleting drivers first.
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Canon iR-ADV C2020/2030 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Generic 50/42/36BW-2 PCL"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Canon iR-ADV C5045/5051 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "KONICA MINOLTA 423SeriesPCL"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Canon iR-ADV C5235/5240 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Canon iR-ADV C5250/5255 UFR II"
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "KONICA MINOLTA 554eSeriesPCL"

rem Install Canon iR-ADV C2030
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.8.23" -h "10.2.8.23" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Canon iR-ADV C2020/2030 UFR II" -i "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" -h "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver" -v 3 -e "Windows x64"
rem printui.exe /b "Canon 4th Floor - Color" /x /h "x64" /n "Canon 4th Floor - Color" /if /f "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver;" /r "IP_10.2.8.23" /m "Canon iR-ADV C2020/2030 UFR II" /u
rem printui.exe /b "Canon 4th Floor - Black and White" /x /h "x64" /n "Canon 4th Floor - Black and White" /if /f "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver;" /r "IP_10.2.8.23" /m "Canon iR-ADV C2020/2030 UFR II" /u

rem Install Canon iR-ADV C5235
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.23" -h "10.2.10.23" -y "public" -o "raw" -n 9100
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Canon iR-ADV C5235/5240 UFR II" -i "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" -h "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver" -v 3 -e "Windows x64"
printui.exe /b "Canon 1st Floor - Color" /x /h "x64" /n "Canon 1st Floor - Color" /if /f "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver;" /r "IP_10.2.10.23" /m "Canon iR-ADV C5235/5240 UFR II" /u
printui.exe /b "Canon 1st Floor - Black and White" /x /h "x64" /n "Canon 1st Floor - Black and White" /if /f "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver;" /r "IP_10.2.10.23" /m "Canon iR-ADV C5235/5240 UFR II" /u

rem Install Konica Minolta
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.18" -h "10.2.10.18" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.17" -h "10.2.10.17" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "KONICA MINOLTA 423SeriesPCL" -i "`0.2.8.31\IS\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64\KOAYXJ__.INF" -h "`0.2.8.31\IS\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64" -v 3 -e "Windows x64"
rem printui.exe /x /b "Konica Minolta (near Circ.)" /n "Konica Minolta (near Circ.)" /if /f "`0.2.8.31\is\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64\KOAYXJ_.INF" /l "`0.2.8.31\is\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64" /r "IP_10.2.10.17" /m "KONICA MINOLTA 423SeriesPCL" /u
rem printui.exe /x /b "Konica Minolta (near Legal)" /n "Konica Minolta (near Legal)" /if /f "`0.2.8.31\is\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64\KOAYXJ_.INF" /l "`0.2.8.31\is\drivers\Konica\423_Series_PS_PCL_FAX_v1.2.0.0\Drivers\PCL\EN\Win_x64" /r "IP_10.2.10.18" /m "KONICA MINOLTA 423SeriesPCL" /u

rem KONICA MINOLTAS REMOVED AS OF 6-21-16
rem Install Konica Minolta
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.19" -h "10.2.10.19" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.18" -h "10.2.10.18" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.17" -h "10.2.10.17" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "KONICA MINOLTA 554eSeriesPCL" -i "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64\KOAYJJ__.INF" -h "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64" -v 3 -e "Windows x64"
rem printui.exe /x /b "Konica Minolta (near Circ.)" /n "Konica Minolta (near Circ.)" /if /f "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64\KOAYJJ_.INF" /l "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64" /r "IP_10.2.10.17" /m "KONICA MINOLTA 554eSeriesPCL" /u
rem printui.exe /x /b "Konica Minolta (near Legal)" /n "Konica Minolta (near Legal)" /if /f "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64\KOAYJJ_.INF" /l "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64" /r "IP_10.2.10.18" /m "KONICA MINOLTA 554eSeriesPCL" /u
rem printui.exe /x /b "Konica Minolta (near Adver.)" /n "Konica Minolta (near Adver.)" /if /f "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64\KOAYJJ_.INF" /l "`0.2.8.40\shrute\is\drivers\Konica\KONICA_MINOLTA_554eSeriesPCL\Drivers\PCL\EN\Win_x64" /r "IP_10.2.10.19" /m "KONICA MINOLTA 554eSeriesPCL" /u

rem Install OCe VL4222
rem escript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.8.18" -h "10.2.8.18" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.8.20" -h "10.2.8.20" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Generic 50/42/36BW-2 PCL" -i "`0.2.8.31\IS\drivers\oce\EN\Win_x64\KOBZEJA_.inf" -h "`0.2.8.31\IS\drivers\oce\EN\Win_x64" -v 3 -e "Windows x64"
rem printui.exe /x /b "OCe VL4222 (near Online)" /n "OCe VL4222 (near Online)" /if /f "`0.2.8.31\IS\drivers\oce\EN\Win_x64\KOBZEJA_.inf" /l "`0.2.8.31\IS\drivers\oce\EN\Win_x64" /r "IP_10.2.8.18" /m "Generic 50/42/36BW-2 PCL" /u
rem printui.exe /x /b "OCe VL4222 (near Art)" /n "OCe VL4222 (near Art)" /if /f "`0.2.8.31\IS\drivers\oce\EN\Win_x64\KOBZEJA_.inf" /l "`0.2.8.31\IS\drivers\oce\EN\Win_x64" /r "IP_10.2.8.20" /m "Generic 50/42/36BW-2 PCL" /u

rem Install Canon iR-ADV C5045
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.8.21" -h "10.2.8.21" -y "public" -o "raw" -n 9100
rem cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Canon iR-ADV C5045/5051 UFR II" -i "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" -h "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver" -v 3 -e "Windows x64"
rem printui.exe /b "Canon 3rd Floor - Color" /x /h "x64" /n "Canon 3rd Floor - Color" /if /f "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver;" /r "IP_10.2.8.21" /m "Canon iR-ADV C5045/5051 UFR II" /u
rem printui.exe /b "Canon 3rd Floor - Black and White" /x /h "x64" /n "Canon 3rd Floor - Black and White" /if /f "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.31\IS\drivers\canon\UFRII_v20.70_Setup_x64\Driver;" /r "IP_10.2.8.21" /m "Canon iR-ADV C5045/5051 UFR II" /u

rem Install Canon iR-ADV C5250
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_10.2.10.21" -h "10.2.10.21" -y "public" -o "raw" -n 9100
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Canon iR-ADV C5250/5255 UFR II" -i "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" -h "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver" -v 3 -e "Windows x64"
printui.exe /b "Canon 2nd Floor - Color" /x /h "x64" /n "Canon 2nd Floor - Color" /if /f "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver;" /r "IP_10.2.10.21" /m "Canon iR-ADV C5250/5255 UFR II" /u
printui.exe /b "Canon 2nd Floor - Black and White" /x /h "x64" /n "Canon 2nd Floor - Black and White" /if /f "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver\CNLB0UA64.INF" /l "`0.2.8.40\shrute\is\drivers\canon\UFRII_v21.05_Setup_x64\Driver;" /r "IP_10.2.10.21" /m "Canon iR-ADV C5250/5255 UFR II" /u

rem Set the BW profile for the Canon's
rem printui /n "Konica Minolta (near Adver.)" /Ss /a "C:\Users\%username%\Desktop\Adverprofile.dat" c u 7
rem i
printui /n "Canon 2nd Floor - Black and White" /Sr /a "`0.2.8.40\shrute\is\drivers\canon\c5250bwprofile.dat" c u 7
printui /n "Canon 1st Floor - Black and White" /Sr /a "`0.2.8.40\shrute\is\drivers\canon\c5235bwprofile.dat" c u 7
printui /n "Canon 2nd Floor - Color" /Sr /a "`0.2.8.40\shrute\is\drivers\canon\c5250colorprofile.dat" c u 7
printui /n "Canon 1st Floor - Color" /Sr /a "`0.2.8.40\shrute\is\drivers\canon\c5235colorprofile.dat" c u 7
rem printui /n "Konica Minolta (near Circ.)" /Sr /a "`0.2.8.40\shrute\is\drivers\Konica\Circprofile.dat" c u 7
rem printui /n "Konica Minolta (near Legal)" /Sr /a "`0.2.8.40\shrute\is\drivers\Konica\Legalprofile.dat" c u 7
rem printui /n "Konica Minolta (near Adver.)" /Sr /a "`0.2.8.40\shrute\is\drivers\Konica\Adverprofile.dat" c u 7

rem Set the default printer.
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p "Canon 2nd Floor - Black and White" -r "IP_10.2.10.21"