Break ON
$=SetOption("Explicit","ON")
Dim $sOldSrv,$sNewSrv,$sOldSrc,$asPrt,$sPrt,$sDefPath,$sDefPrt,$sDefSrv
Dim $iVerbose, $iMapped
$iVerbose=1 ; 1=Display debug messages, 0=Don't display
$sOldSrv="pserver1"
$sNewSrv="vhost"
$asPrt ="6thFloorCanon","6thFloorFieldCrew1","EngineeringPlotter_HPGL2",
"EngineeringPlotterPS","FIN_P1505N","HP4_2100","HP4_ACR","HP4_Creative",
"HP4_Engineer","HP4_Exec","HP4_Field","HP4_FINANCE","HP4_Online","HP4_OPS",
"HP4_Ops2","HP4_Prog1","HP4_Prog2","HP4_Prog3","HP4_Radio","HP4_TapeOps",
"HP4_VTL","HP5 Graphics","HP5_Aquarius","HP5_HR","HP5_Ops","HP5WJColor",
"HP_LJ1505","Phaser 8400N PS","RADIO_LJ1022n"
$sDefPath=GetDefaultPrinter()
$sDefSrv=Split($sDefPath+"\\\","\")[2]
$sDefPrt=Split($sDefPath+"\\\","\")[3]
If $iVerbose "[DBG] Default printer server='"+$sDefSrv+"', share='"+$sDefPrt+"'"+@CRLF EndIf
; ***
; Check if the default printer is in the list, AND is mapped to the old server.
; ***
If AScan($asPrt,$sDefPrt)+1 AND $sDefSrv=$sOldSrv
$iMapped=PriMapState("\\"+$sNewSrv+"\"+$sDefPrt)
; ***
; If the printer is not yet mapped to the new server then map it.
; ***
If Not $iMapped
If AddPrinterConnection("\\"+$sNewServer+"\"+$sDefPrt)
"Could not map printer server='"+$sDefSrv+"', share='"+$sDefPrt+"'"+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
$iMapped=1
If $iVerbose "[DBG] Mapped printer server='"+$sDefSrv+"', share='"+$sDefPrt+"'"+@CRLF EndIf
EndIf
EndIf
; ***
; Only set the default if the printer is mapped and is not already the default.
; ***
If $iMapped=1
If SetDefaultPrinter("\\"+$sNewSrv+"\"+$sDefPrt)
"Could not set printer "+$sDefPrt+" on server "+$sNewSrv+" as default"+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
"Printer "+$sDefPrt+" on server "+$sNewSrv+" set as default"+@CRLF
endif
EndIf
EndIf
; Lonkero's Shrink-wrapped primter mapping state check funtion.
function PriMapState($_Pri)
if @inwin=1
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
else
dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
for $_C=0 to 259
$_C2=enumkey($_Root,$_C)
If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
$PriMapState = 2
Else
$PriMapState = 1
Endif
Endif
if $_C2=259 $_C=$_C2 endif
next
endif
endfunction
Function GetDefaultPrinter()
$GetDefaultPrinter = Join(Split(ReadValue("HKEY_USERS\" + @sid + "\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device"), ',', 1), '')
EndFunction