If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption("Explicit", "ON")
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("WrapAtEOL", "ON")
Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL
$OldServer = "\\cmi-25"
$NewServer = "\\nsfcmi-4"
$ArrPtrs = Split("Printer1,Printer2,Printer3",",")
For Each $Ptr In $ArrPtrs
$PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr)
If 0 < $PtrMapState
$NUL = AddPrinterConnection("\\" + $NewServer + "\" $Ptr)
If NOT @ERROR AND 2 = $PtrMapState
$NUL = SetDefaultPrinter("\\" + $NewServer + "\" $Ptr)
If @ERROR
? "Error setting default Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
Else
? "Error adding Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
If NOT @ERROR
$NUL = DelPrinterConnection($Ptr)
If @ERROR
? "Error deleting Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
EndIf
EndIf
Next
;FUNCTION PriMapState
;
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;
;ACTION Checks for existent networkprinter connection
;
;VERSION 1.1.1
;
;CHANGES 1.1.1 - 01. november 2003
; Fixed buggie descriped in:
; http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=008079
; 1.1 - 02. July 2002
; added support for win9x
; 1.0 - 01. July 2002
; initial release
;
;SYNTAX PriMapState(PRINTER)
;
;PARAMETERS PRINTER
; to be checked Printer's name
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;
;REMARKS code for w9x adapted from BrianTX
;
;DEPENDENCIES none
;
;EXAMPLE
; if not PriMapState('\\server\printer1')
; "printer1 not connected!"
; endif
;
;CODE
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