2003-12-16, 03:17 PM
When you conduct a print server migration, you must consider the best method for moving your users off the old print servers and onto the new servers. You can manually change each user's installed printers, although this task is time-consuming. Alternatively, you can use a third-party tool or logon scripting with Active Directory's (AD's) Group Policy to automatically install new printers.
Automatic methods typically involve giving users access to the new printers without limiting their access to the old printers, then guiding users in selecting their new default printers and deleting the old printer names. This type of scenario can be problematic because if users don't follow instructions correctly, they can experience dead printer connections after you decommission the old print servers. The VBScript code prevents these problems when you run it at logon.
To run the script, you need a list of your old and new print queue names in a comma-separated text file. I used C:\printers.txt for the file location, but you can also use a network share. You need to use the following format for the script to work:
\\oldserver\oldprinter,
\\newserver\newprinter
[VBScript code]
Logon Script to Automatically Install New Printers
On error resume next
' This code enumerates the user's current network printer connections.
Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For j = 0 to oPrinters.Count - 1 Step 2
' This code opens a comma-delimited text file containing
' the corresponding old and new printers and assigns
' each line as an array variable.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:\printers.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrPrinterList = Split(strNextLine , ",")
' This section retrieves the registry value corresponding to the
' default printer and assigns the registry value as a string variable.
const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
strValueName = "Device"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
wscript.echo(strValue)
' This code takes both variables defined above and introduces conditional logic.
For i = 1 to Ubound(arrPrinterList)
If strValue =(arrPrinterList(0)) then
Wscript.Echo "Your default printer will be changed to: " & arrPrinterList(i)
WshNetwork.AddWindowsPrinterConnection arrPrinterList(i)
WshNetwork.SetDefaultPrinter arrPrinterList(i)
WshNetwork.RemovePrinterConnection arrPrinterList(0)
Else
If oPrinters.Item(j+1)=arrPrinterList(0) then
WshNetwork.RemovePrinterConnection arrPrinterList(0)
WshNetwork.AddWindowsPrinterConnection arrPrinterList(i)
End If
End If
wscript.sleep 15000
Next
Loop
Next
wscript.echo "<Insert optional notification here.>"