Break on
;Enumerate the current (old) printer connections.
$printers = ArrayEnumKey("HKEY_CURRENT_USER\Printers\Connections")
;Get the default printer.
;Why? See If - Endif statement below.
$defaultprinter = GetDefaultPrinter()
;Split the default printername on \.
;This makes an array you can reference to an element later.
$defaultprinter = Split($defaultprinter, "\")
;Get just the default printer name. Strip off the server name.
;Get the contents of the highest element in the array created above.
$defaultprintername = $defaultprinter[Ubound($defaultprinter)]
;Do stuff for each printer found.
For Each $printer in $printers
;
;Split the key name on ,.
;This makes an array you can reference to an element later.
$printersplit = Split($printer, ",")
;
;Get just the printer name. No server, no comma's.
;Get the contents of the highest element in the array created above.
$printername = $printersplit[Ubound($printersplit)]
;
;Delete the old printer.
$rc = DelKey("HKEY_CURRENT_USER\Printers\Connections\" + $printer)
;
;Connect the same printer but with the new server name.
$rc = AddPrinterConnection("\\newserver\" + $printername)
;
;If the printer being added is the same as the old default printer then
;set the new printer as default.
If $printername = $defaultprintername
;Set the default printer.
$rc = SetDefaultPrinter("\\newserver\" + $printername)
EndIf
Next
;=-=-=-=--= DO NOT MODIFY ANYTHING BELOW THIS LINE =-=-=-=--=
;=-=-=-=--= BELOW ARE UDF'S. THEY COME READY MADE. =-=-=-=--=
;HKEY_CURRENT_USER\Printers\Connections\,,jupiter,RTD-PRN003
;NAME ArrayEnumKey
;
;ACTION Creates an array of names of the subkeys contained in a registry key or subkey
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.2 (added error codes)
; 1.1
;
;DATE CREATED 2001/12/05
;
;DATE MODIFIED 2003/05/17
;
;KIXTART 4.12+
;
;SYNTAX ARRAYENUMKEY($subkey)
;
;PARAMETERS SUBKEY
; Required string containing the key or subkey for which the subkeys will be enumerated
;
;RETURNS Array containing the subkeys
;
;REMARKS none
;
;DEPENDENCIES none
;
;EXAMPLE $retcode=arrayenumkey('HKEY_USERS')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000064
;
Function arrayenumkey($regsubkey)
Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray
If NOT KeyExist($regsubkey)
Exit 87
EndIf
$subkeycounter=0
Do
$currentsubkey=EnumKey($regsubkey,$subkeycounter)
If NOT @ERROR
ReDim preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
EndIf
Until @ERROR
$arrayenumkey=$subkeyarray
Exit 0
EndFunction
;FUNCTION GetDefaultPrinter()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION 1.0
;
;VERSION HISTORY 1.0 2004/04/28 Initial release
;
;ACTION Retrieves the current default Printer
;
;SYNTAX GetDefaultPrinter()
;
;PARAMETERS none
;
;REMARKS won't work with 9x OS
;
;RETURNS The current Users default Printer
;
;DEPENDENCIES None !
;
;EXAMPLES $default = GetDefaultPrinter
Function GetDefaultPrinter()
$GetDefaultPrinter = Join(Split(ReadValue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
EndFunction