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
suresh187Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sekar ChinnakannuStaff EngineerCommented:
Command to map the printer Net use \\fileserver\sharedPrinter /persistent:yes make sure user have right to run same.
0
kemi67Commented:
Do you mean something like suggested here?
http://www.computerperformance.co.uk/Logon/LogonScript_Printer.htm

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

Open in new window

0
suresh187Author Commented:
Sekarc4u: tried that it would'nt run

Kemi67: prefer if it wasn't VB
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

chakkoCommented:

For DOS batch file you can try this
prnmngr.vbs

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]
Arguments:
-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

Examples:
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"






0
chakkoCommented:
the prnmngr.vbs should be included in the Windows\System32 folder already.
0
footechCommented:
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:
http://download.microsoft.com/download/8/2/c/82cffcfa-56f6-4fc3-bfa5-80cd84793871/PrintUIUsersGuide.doc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
johnb6767Commented:
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"


exit

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.