Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


December 04, 2007

Is there a script that will replace my current network printers with printers on a separate print server?

RSS
Subscribe to Windows IT Pro | See More Printing Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A. Yes, there is. If you use Group Policy to deploy printers, it's easy to move users to other printers by simply updating the deployed printers. However, unless you're using Windows Server 2008, that process can be tricky.

Randy Foster has written a script that parses the client registry and replaces one print server with another. The printer shares must be similarly named on both the old and new print servers. I reproduce Randy's script here, complete with all his comments. Notice the need to replace the cosrv and co-data-01 values on the new print server.

'Author - Randy Foster
'Email - rfoster_2000@excite.com
'MCSE NT4, 2000
'MCSA 2003
'MCDBA SQL7, SQL2000
'CCNA

'This script works well in a login script. When ran from a workstation
'it will loop thru all of the printers installed for the current logged on
'user and if they are connected to the old server they will be removed
'and then remaped to the new server. It will also attempt to descover
'which printer is the default printer in order to reset this if it is one
'of the printers that will be moved.

'Note: All of the printers must exist on the new server before this script
' should be run. If not then the printer will simply be removed from
' users profile and the script will not be able to reconnect them.
' "Print Migrator" is a utility that is part of the Windows 2000 and
' Windows 2003 resource kit. This will create all of the printers
' on the new server while maintaining all of their settings including
' print queue security. Keep in mind that for a time you will see
' duplicate printer if you do a search on printers, one advertisec
' from each server.

'We used this method to move just over 100 printers from one server to another
'and then ran this script as a logon script in a group policy. We let it run for
'a few days in order to allow for some users who don't logout every day have a
'chance to run it. All of our users profiles were updated and they didn't even
'know it was happening. We then deleted all of the printers from the old server.

'Note: The script does not run if you are Terminal serviced or SMS remote controling.

Option Explicit
Dim from_sv, to_sv, PrinterPath, PrinterName, DefaultPrinterName,
DefaultPrinter
Dim DefaultPrinterServer, SetDefault, key
Dim spoint, Loop_Counter
Dim WshNet, WshShell
Dim WS_Printers
DefaultPrinterName = ""
spoint = 0
SetDefault = 0
set WshShell = CreateObject("WScript.shell")

from_sv = "\\cosrv" 'This should be the name of the old server.
to_sv = "\\co-data-01" 'This should be the name of your new server.

'Just incase their are no printers and therefor no defauld printer set
' this will prevent the script form erroring out.

On Error Resume Next
key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
DefaultPrinter = LCase(WshShell.RegRead (key))
If Err.Number <> 0 Then
DefaultPrinterName = ""
else

'If the registry read was successful then parse out the printer name so we can
' compare it with each printer later and reset the correct default printer
' if one of them matches this one read from the registry.

spoint = instr(3,DefaultPrinter,"\")+1
DefaultPrinterServer = left(DefaultPrinter,spoint-2)
if DefaultPrinterServer = from_sv then
DefaultPrinterName = mid(DefaultPrinter,spoint,len(DefaultPrinter)-spoint+1)
end if
end if
Set WshNet = CreateObject("WScript.Network")
Set WS_Printers = WshNet.EnumPrinterConnections

'You have to step by 2 because only the even numbers will be the print queue's
' server and share name. The odd numbers are the printer names.

For Loop_Counter = 0 To WS_Printers.Count - 1 Step 2

'Remember the + 1 is to get the full path ie.. \\your_server\your_printer.

PrinterPath = lcase(WS_Printers(Loop_Counter + 1))

'We only want to work with the network printers that are mapped to the original
' server, so we check for "\\Your_server".

if LEFT(PrinterPath,len(from_sv)) = from_sv then

'Now we need to parse the PrinterPath to get rhe Printer Name.

spoint = instr(3,PrinterPath,"\")+1
PrinterName = mid(PrinterPath,spoint,len(PrinterPath)-spoint+1)

'Now remove the old printer connection.

WshNet.RemovePrinterConnection from_sv+"\"+PrinterName

'and then create the new connection.

WshNet.AddWindowsPrinterConnection to_sv+"\"+PrinterName

'If this printer matches the default printer that we got from the registry then
' set it to be the default printer.

if DefaultPrinterName = PrinterName then
WshNet.SetDefaultPrinter to_sv+"\"+PrinterName
end if
end if
Next
Set WS_Printers = Nothing
Set WshNet = Nothing
Set WshShell = Nothing

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Windows 7 Sets Sales Record

Microsoft CEO Steve Ballmer described Windows 7's first ten days of sales as "fantastic" while in Japan yesterday. ...


Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Managing IT Across Multiple Locations

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement