Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Willo,
This looks like an offshoot of my fnRemapDrives() function. I have a new function to remap printers that I haven't posted yet that looks like this...
Break On CLS $NUL=SetOption("Explicit","On") Dim $,$ticks,$rc
$ticks=@ticks $rc = fnRemapPrinters("OldServer","NewServer") ? @ERROR ":" @SERROR If @INWIN=2 and $RC ? "Reboot Required" EndIf ? "Remapped "+ $rc + " Printers in "+(@ticks-$ticks)/1000+" seconds."
Get $
Function fnRemapPrinters($sOldServer,$sNewServer) Dim $lIndex,$sPrinters,$sPrinter,$sServer,$sPrint,$sPort,$sSplit,$lS,$sShare,$NUL,$Err,$sDevice $fnRemapPrinters=0 $lIndex=0 If @INWIN=1 $sPrinters="HKCU\Printers\Connections\" Do $sPrinter=EnumKey($sPrinters,$lIndex) If $sPrinter $sServer=ReadValue($sPrinters+$sPrinter,"Server") If SUBSTR($sServer,3,LEN($sServer))=$sOldServer $sPrint=Split($sPrinter,",") $NUL=DelPrinterConnection("\\"+$sOldServer+"\"+$sPrint[3]) If @ERROR $Err=@ERROR EndIf $NUL=AddPrinterConnection("\\"+$sNewServer+"\"+$sPrint[3]) If @ERROR $Err=@ERROR Else $fnRemapPrinters=$fnRemapPrinters+1 EndIf EndIf EndIf $lIndex=$lIndex+1 Until $sPrinter="" Else $sPrinters="HKLM\System\CurrentControlSet\control\Print\Printers\" Do $sPrinter=EnumKey($sPrinters,$lIndex) If $sPrinter $sPort=ReadValue($sPrinters+$sPrinter,"Port") $sSplit=Split($sPort,"\") If $sSplit[2]=$sOldServer $lS=Len($sPort)-Len($sOldServer)-2 $sShare=Right($sPort,$lS) $NUL=WriteValue($sPrinters+$sPrinter,"Port","\\"+$sNewserver+$sShare,"REG_SZ") If @ERROR $Err=@ERROR EndIf $sDevice=ReadProfileString ("Win.ini", "Windows", "Device") $sDevice=Split($sDevice,",") If $sDevice[2]=$sPort $NUL=WriteProfileString ("Win.ini", "Windows", "Device", $sDevice[0]+","+$sDevice[1]+","+"\\"+$sNewserver+$sShare) If @ERROR $Err=@ERROR EndIf EndIf $NUL=WriteProfileString ("Win.ini", "Ports", $sPort) $NUL=WriteProfileString ("Win.ini", "Ports", "\\"+$sNewserver+$sShare, " ") If @ERROR $Err=@ERROR EndIf $sPrinterPorts=ReadProfileString ("Win.ini", "PrinterPorts", $sPrinter) $sPrinterPorts=Split($sPrinterPorts,",") $NUL=WriteProfileString ("Win.ini", "PrinterPorts", $sPrinter, $sPrinterPorts[0]+","+"\\"+$sNewserver+$sShare+","+$sPrinterPorts[2] +","+$sPrinterPorts[3]) If @ERROR $Err=@ERROR EndIf $sDevices=ReadProfileString ("Win.ini", "Devices", $sPrinter) $sDevices=Split($sDevices,",") $NUL=WriteProfileString ("Win.ini", "Devices", $sPrinter, $sDevices[0]+"," +"\\"+$sNewserver+$sShare) If @ERROR $Err=@ERROR EndIf If Not $Err $fnRemapPrinters=$fnRemapPrinters+1 EndIf EndIf EndIf $lIndex=$lIndex+1 Until $sPrinter="" EndIf If Not $Err $Err=0 EndIf Exit $Err EndFunction
I've tested it and it works. I haven't posted it yet because I was going to test it in against a test server that we're setting up this week.
Anyway, see if this will meet your needs. It is designed to work on Windows 9x computers as well.
|