$oldPrinters = 'Print1', 'Print2', 'Print3', 'Print4', 'Print5', 'Print6'
$defaultprinter = GetDefaultPrinter()
$OldSvr = '\\OldServer\'
$NewSvr = '\\NewServer\'
For Each $Printer in $oldPrinters ; enumerate list of all printer names
If PriMapState($OldSvr + $Printer) ; is it mapped to old server?
AddPrinterConnection($NewSvr + $Printer) ; connect to new server
if not @error
DelPrinterConnection($OldSvr + $Printer) ; disconnect from old
EndIf
EndIf
If $defaultprinter = ($OldSvr + $Printer) ; select old default printer
$rc = SetDefaultPrinter($NewSvr + $Printer)
EndIf
Next ; check next printer
; GetDefaultPrinter UDF Function
function GetDefaultPrinter()
$GetDefaultPrinter = join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction
; PriMapState UDF Function
function PriMapState($_Pri)
if len(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
if split(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri
$PriMapState=2
else
$PriMapState=1
endif
endif
endfunction