We help IT Professionals succeed at work.

Printer batch script for Windows XP/Vista/7

I currently have a batch script running to map network drives with works fine, i would like to add printers to the script for all users.  

Desktops are Windows XP/7 Pro
DC is Windows 2008 R2 x64
Watch Question

Command to map the printer Net use \\fileserver\sharedPrinter /persistent:yes make sure user have right to run same.
Do you mean something like suggested here?

For example, in a vbscript:
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection "\\alan\Epson."

Open in new window


Sekarc4u: tried that it would'nt run

Kemi67: prefer if it wasn't VB


For DOS batch file you can try this

example for batch file:

cscript c:\windows\system32\prnmngr.vbs -ac -p "\\server\Printer Share"

C:\WINDOWS\system32>cscript prnmngr.vbs

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: prnmngr [-adxgtl?][c] [-s server][-p printer][-m driver model]
               [-r port][-u user name][-w password]
-a     - add local printer
-ac    - add printer connection
-d     - delete printer
-g     - get the default printer
-l     - list printers
-m     - driver model
-p     - printer name
-r     - port name
-s     - server name
-t     - set the default printer
-u     - user name
-w     - password
-x     - delete all printers
-?     - display command usage

prnmngr -a -p "printer" -m "driver" -r "lpt1:"
prnmngr -d -p "printer" -s server
prnmngr -ac -p "\\server\printer"
prnmngr -d -p "\\server\printer"
prnmngr -x -s server
prnmngr -l -s server
prnmngr -g
prnmngr -t -p "\\server\printer"

the prnmngr.vbs should be included in the Windows\System32 folder already.
Top Expert 2014
My preferred method is to just use Group Policy.  But if you want to use something in a batch file, here's what I've used before.  Use something like the following in a batch file.
rundll32 printui.dll,PrintUIEntry /ga /n"\\SERVERNAME\PRINTER_SHARE_NAME"
The /ga adds the printer at the machine level, so that any users who log on will have access and not have to separately install.  You didn't mention if this was to be a logon script or a one time thing.  The command  I mentioned doesn't work well as a logon script, as you will see errors when you try to add a connection that already exists.  To remove the printer connection, substitute "/gd" for "/ga".
Here's a reference for PrintUI usage:
Most Valuable Expert 2011
Top Expert 2011

I use something very simple for detecting and refreshing them, could use the same for a logon script.....

This queries the registry to see if it is present. The format is going to be in ",,printserver,queuename" as subkeys
If it finds it, the ERRORLVEL is 0, which the next line skips it.
If it is not a 0, is gets installed.....

Take a look at a system to get the idea, and this should be clear....
@echo off

reg query "HKEY_CURRENT_USER\Printers\Connections" | find /i "QUEUENAME"
if not %errorlevel%==0 start "" "\\server\quenename"

REM for XP, try this syntax.....
REM if not %errorlevel%==0 explorer "\\server\quenename"


Open in new window