Function ChangePrinterName($OldPrinterName, $NewPrinterName)
$printers = arrenumkey('HKCU\Printers\Connections')
For Each $printer in $printers
If InStr($printer,$OldPrinterName)
$printer = Split($printer,',')
$old = '\\' + $printer[2] + '\' + $printer[3]
$new = '\\' + $printer[2] + '\' + $NewPrinterName
$rc = AddPrinterConnection($new)
If Not @error
If Primapstate($old) = 2
$rc = SetDefaultPrinter($new)
EndIf
$rc = DelPrinterConnection($old)
EndIf
EndIf
Next
EndFunction
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
Function arrenumkey($regkey)
Dim $Keylist, $c
If Not KeyExist($regkey)
Exit 87
EndIf
Do
$Key = $Key+'|'+EnumKey($regkey,$c)
$c = $c + 1
Until @error
$arrenumkey = Split(SubStr($Key,2,Len($Key)-2),'|')
EndFunction