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?
 
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
 
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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

Kemi67: prefer if it wasn't VB
0
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.