For anyone trying to solve a similar issue with moving the ad-hoc end-user
printer connections over in the wake of a wholesale printserver migration,
here's a sample script that can help. The best solution, as Alan Morris
pointed out, is a server rename. If that's not an option (printers were on a
multi-role server still in use, name restrictions, etc) the following chunk
of VBScript can be used to remap Windows-based printer connections from the
old server to the new one.
I've made some comments inline about the process, but those and a couple of
other points are worth mentioning.
+ user customizations such as preferred printer and feature customization
don't get carried over; this is just a remap-and-delete;
+ You need to have identical names for the queues on the new server;
+ LPT/COM port redirection isn't handled;
+ If there are problems when the script is run - new server not available,
etc - there will be a several second delay for each connection attempt. To
mitigate the impact, the script will quit trying to remap queues after two
attempts have failed, and it never deletes the old queue until the new one
has been set.
dim net: Set net = CreateObject("WScript.Network")
OldPrintServer = "ws2003e02"
NewPrintServer = "PSrv2k8"
Dim PConnections
set PConnections = net.EnumPrinterConnections()
' Manually pad the names for the servers.
' Doing it this way should reduce administrator
' errors slightly.
' Or not. However, it lets us enter the names
' in a cleaner fashion and doesn't force people
' to remember where to put how many (\)s.
OldPrintRoot = "\\" & OldPrintServer & "\"
NewPrintRoot = "\\" & NewPrintServer & "\"
' Following reduces list to only UNC paths (or
' names for local printers)
Redim Queues(PConnections.count/2)
for i = 1 to PConnections.count step 2
Queues((i-1)/2) = PConnections(i)
next
' Reduce queues to ONLY those with the old print root
OldQueues = Filter(Queues, OldPrintRoot, True, vbTextCompare)
'WScript.Echo Join(OldQueues, vbCrLf)
' If NewPrintServer isn't up yet, there will be significant
' pause (15-45 sec) while AddWindowsPrinterConnection times out.
' for that reason, we want to quit trying if it doesn't work.
' The following loop tries to remap each queue. If it succeeds,
' the old mapping is deleted.
' If it fails for two queues during the process, we quit trying.
' This is intentional; you don't want a user with 10 print queues
' mapped to wait for 7-8 minutes while the logon script does nothing.
Dim failures: failures = 0
For Each OldQueue in OldQueues
NewQueue = Replace(OldQueue, OldPrintRoot, NewPrintRoot)
On Error Resume Next
Net.AddWindowsPrinterConnection(NewQueue)
'could test err.number, but this lets us stop
' error suppression immediately.
errnum = err.number
On Error Goto 0
if err.number = 0 Then
' remap succeeded; kill the old queue
' We want to force it if necessary, AND update profile.
Net.RemovePrinterConnection OldQueue, False, False
else
failures = failures + 1
' One failure might be a glitch. Two failures means
' a problem somewhere; stop slowing down progress
' and exit the For-Next loop.
'WScript.Echo Hex(Err.Number)
If failures > 1 Then Exit For
end if
Next