Solved

Adding TCP/IP printers with batch

Posted on 2004-10-14
8
2,249 Views
Last Modified: 2011-02-15

Win2000 and XP workstations need new printers installed

Everyones printer and faxes window is cluttered with old unused printers that need to be removed.
Original configuration was a TCP/IP port directly (to the printer with static IP address) from each workstation.
Then I was told to go to Print Shares on the server. Which I did.
This current configuration the queue's are always getting jammed and I spend a lot of my day unjamming them.
They would now like me to add a new TCP/IP port by (host name of the printer) because the printers no longer have static IP address and are now configured by DHCP.

What I do now is:
Add printer
New printer
Create a new port
Standard TCP/IP port
printer name or tcp/ip address (I enter the host name here)
Done

How can I automate this? I've got over 200 computers to do.

First I'd like to remove ALL current printers on machine weather they be attached to the server or ported directly to the printer and then have a batch or some other script to automate the above printer install.

Thanks
Yohaheho
0
Comment
Question by:Yohaheho
8 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 12307975
It appears like all this information is stored in the registry. I looked for one of my printers and found it under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print

You could create a printer and then export the registry entry to a file. You could maybe create all the printers you want to install and export to a file at the Print level.

Then you could use "reg delete" to delete all printers and then "reg import" to save the new entries.

Good Luck,
Steve
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12308709
I think you have other problems if your printers are getting jamed.  I had a network of 600+ Windows PCs and one print server and things rarely jammed.  Of course, it does depend on your environment, but these things are supposed to que up so that they all print out over time.  In addition, you could have setup Printer Pooling if you have identical printers.  Then whichever printer was free would spit out the document(s).

In my opinion, putting TCP/IP printers on workstations directly - especially when there's more than a few workstations, is a tremendous waste of time and effort.

That aside, the Windows Management Instrumentation (WMI) should be able to do what you are asking.  If you wanted to script it, I'd suggest studying up on that (unfortunately, I never used it myself, but one of my former coworkers did write a script using WMI that changed print servers and removed old dead printers.
0
 
LVL 6

Expert Comment

by:tanelorn
ID: 12309922
herfe's a vbscript that will add a printer.
there is some commented out lines (witn the preceding '  )
if you want to hard code it, just add more printerpath lines followed by the AddWindowsPrinterConnection calls

##########snip############
dim WshShell, WshNetwork, PrinterName, default

'printerName = InputBox("Which printer do you want to install :adcptXX","Which printer?","adcpt60")

'default = MsgBox("do you want this as your default printer?", vbYesNo ,"Default Printer?")
Set WshNetwork = WScript.CreateObject("WScript.network")

'to hard code put printername inside the quotes and remove the ampersand and 'PrinterName'
PrinterPath = "\\printserver\" & PrinterName  
WshNetwork.AddWindowsPrinterConnection PrinterPath

'if default = y then
'WshNetwork.SetDefaultPrinter PrinterPath

'End If
############snip#############

and here is a script that will remove all printers that are mapped..  if you need it...

(plagerized from http://www.dbforums.com/archive/index.php/t-774023.html  )

############snip###############

set wshNetwork = CreateObject ("WScript.Network")
'deletes all network printers
Set clPrinters = WshNetwork.EnumPrinterConnections
On Error Resume Next
For i = 0 to clPrinters.Count - 1 Step 2
wshNetwork.RemovePrinterConnection clPrinters.Item(i+1), true
Next


################snip###############
you could add this as part of the login script   (put the remover first...)
and configure the addprinter script with the printers that you want the users to have..



let me know if this helps.  
Tanelorn

0
 
LVL 10

Accepted Solution

by:
Longbow earned 500 total points
ID: 12318304
* You can check these scripts if they are useful for you :
http://cwashington.netreach.net/depo/view.asp?Index=358&ScriptType=vbscript

http://cwashington.netreach.net/depo/view.asp?Index=555&ScriptType=vbscript

 * Install a printer using rundll32.exe :
http://www.dx21.com/SCRIPTING/RUNDLL32/ViewItem.ASP?OID=145
You can use psexec to execute this command with admin rights :
Pstools Suite found at http://www.sysinternals.com

 * Psexec run like the RunAs command.
The user doubli-click a shortcut and psexec executes your Rundll command with the account you want.
You need to choose the Rundll32 you want to run.

 * A script to use with Rundll32 :
'Beginning of VbScript
'Save in a .vbs file
'Add the paths where needed:
Set WshShell = WScript.CreateObject("WScript.Shell")
Command = "psexec -u Domain\Admin -p password " & CHR(34) & "rundll32.exe" & CHR(34) & "syntax"
msgbox Command
WshShell.Run Command, 1, false
'End of VbScript

The VB Script can be encoded.
Or create a user for the occasion.
http://www.microsoft.com/downloads/details.aspx?FamilyId=E7877F67-C447-4873-B1B0-21F0626A6329&displaylang=en

 * You can use Sysdiff to find the registry changes. It is in the Resource Kit.
Addendum for Sysdiff :
http://www.microsoft.com/windows2000/techinfo/reskit/tools/hotfixes/sysdiff-o.asp
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:Longbow
ID: 12318425
HOW TO: Programmatically Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script in Microsoft Windows 2000 :
http://www.kbalertz.com/Feedback_321025.aspx

Original article :
http://support.microsoft.com/default.aspx?scid=kb;EN-US;321025

Find normally Prnadmin.dll in the Windows 2000 Resource Kit.
0
 
LVL 10

Expert Comment

by:Longbow
ID: 12318469
0
 
LVL 3

Expert Comment

by:browolf
ID: 12341526
You can add printers using batch. the easiest way is to rename your computer names so they include an id for the area which they  reside and then printer script assigns printers based on the area from the computername. when i get to work tomorrow will post the script i use that functions in this manner.  
0
 

Author Comment

by:Yohaheho
ID: 12439948
Everyone,

Sorry this took so long. I just got it figured out. It’s a bit long but saves a lot of time in the end. I’ll just lay out snips of the 3 batch files I created. You could probably combine them into one if you wanted to but I left it in 3 so you could easily see the 3 different functions that would be performed. I pushed these batch files out with psexec and Altiris.

Thanks for the help
Yohaheho

Batch file # 1 deleting all the old printers.
:: The "PrintUIEntry" is case sensative!!!
:: This does not remove the driver or the port just the printer from the printers window
:: At the begining of the cmd window it states that UNC paths are not supported but is
:: still runs for me :)

:: This is to remove a locally installed printer (TCP/IP or LTP)
:: The printer name at the end of each line is the name as it appears in the printers page

rundll32 printui.dll,PrintUIEntry /dl /q /n "acrobat distiller"
rundll32 printui.dll,PrintUIEntry /dl /q /n "hp4050 - rm142"
rundll32 printui.dll,PrintUIEntry /dl /q /n "hp4100 - media center"

:: This is to remove a network mapped printer from a server
:: (This removes printers from the local workstation not the server!)
:: HEY... READ THE NEXT LINE CAREFULLY
:: The printer name at the end of each line is the path and name as it appears on the SERVER!!!

rundll32 printui.dll,PrintUIEntry /dn /q /n "\\myserver\hp4100-media center"
rundll32 printui.dll,PrintUIEntry /dn /q /n "\\myserver\hp4100-rm101-107"
exit


Batch file # 2 Adding printer ports to a computer
:: This batch file installs a registry key to add TCP/IP and or host name ports to a computer
:: You can edit the reg key and add your own schools ports
:: This must run with Admin rights
:: At the begining of the cmd window it states that UNC paths are not supported but it
:: still runs for me :)

@echo off
regedit /s "\\myserver\Utilities\printer ports.reg"
net stop spooler
Ping -n 5 127.0.0.1>nul
net start spooler
exit

Here is a snip from the reg file.
Windows Registry Editor Version 5.00
rem Read the remed out statements just below for information on how to add your own ports.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports]
"StatusUpdateInterval"=dword:0000000a
"StatusUpdateEnabled"=dword:00000001

rem In each of the following keys there is only 2 places you need to make changes so this file will suit your
rem school. At the end of the first line change that to an IP_Address or host name of printer. Then on either
rem the 4th or 5th line you will have to enter the same information depending on whether you are adding a port
rem by TCP/IP or by printer host name.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_10.247.110.13]
"Protocol"=dword:00000001
"Version"=dword:00000001
"HostName"=""
"IPAddress"="10.247.110.13"
"HWAddress"=""
"PortNumber"=dword:0000238c
"SNMP Community"="public"
"SNMP Enabled"=dword:00000001
"SNMP Index"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\npi317a70]
"Protocol"=dword:00000001
"Version"=dword:00000001
"HostName"="npi317a70"
"IPAddress"=""
"HWAddress"=""
"PortNumber"=dword:0000238c
"SNMP Community"="public"
"SNMP Enabled"=dword:00000001
"SNMP Index"=dword:00000001


Batch file # 3 Adding printers and drivers
:: The port must already be on the computer for this to add the printer!
:: At the begining of the cmd window it states that UNC paths are not supported but is
:: still runs for me :)

:: /b = "Name people will see in printers window"
:: /f = "path to printer driver .inf file"
:: /r = "host name of printer"
:: /m = "printer driver model name"

rundll32 printui.dll,PrintUIEntry /if /b "Media Center" /u /f "\\myserver\Utilities\Printer drivers\4200w2k&xp drivers\hp4200p6.inf" /r "npib36c08" /m "HP Laserjet 4200 PCL 6" /z

:: I put this in because if you keep clicking the batch file it will produce multiple copies of the printer.
:: This will make sure that doesn't happen. Make sure in quotes it has the same name as the /b switch uses
:: in the line above.

rundll32 printui.dll,PrintUIEntry /dl /q /n "Media Center (copy 2)"
rundll32 printui.dll,PrintUIEntry /dl /q /n "Media Center (copy 3)"
exit


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now