dim net: Set net = CreateObject("WScript.Network")
OldPrintServer = "ws2003e02"
NewPrintServer = "PSrv2k8"
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)
for i = 1 to PConnections.count step 2
Queues((i-1)/2) = PConnections(i)
' 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
'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
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.
If failures > 1 Then Exit For