Printers, been there, done that. Changing queues, servers, hell, even renaming them. Renaming them unfortunately is a complex process, thank god for the SetFocus & SendKeys command. This script even takes care of printers captured via LPT ports. Here's the code. It's a bit complex, so if you are new to Kix you might get scared.

This file uses a text file for converting the queues, "printers.txt". The format is:

\\oldserver\oldqueuename,\\newserver\newqueuename

--
$scriptpath="c:\locationofyourscriptfiles"

; Printer Section
; This section searches the registry for the current network printer ports, and replaces
; them with a new port as specified in the printers.txt file.
; The code for these routines was very complex. Please be careful when modifying!!

? ? ? "Updating printers..." ?
$prnrenfile = "%windir%\prnren.txt"
$prnfile = $scriptpath+"\printers.txt"
if (exist($prnfile) = 0)
color r+/n
? ? $prnfile+" file not found! Skipping printers section..." ? ?
shell "%comspec% /c pause"
color w/n
else
del $prnrenfile
$nul=open(9,$prnrenfile,5)
$updatedprinters=0

? "Detecting captured printer ports..." ?
$key = "HKEY_CURRENT_USER\Network\Persistent"
$index = 0
$subkey = enumkey($key, $index)
while (@ERROR = 0)
if (instr($subkey,"LPT") = 1)
$value=readvalue($key+"\"+$subkey,"RemotePath")
if (@ERROR = 0)
? "Captured LPT port found: "+$subkey+" - "+$value
select
case ($subkey = "LPT1")
$lpt1 = $value
case ($subkey = "LPT2")
$lpt2 = $value
case ($subkey = "LPT3")
$lpt3 = $value
case ($subkey = "LPT4")
$lpt4 = $value
case ($subkey = "LPT5")
$lpt5 = $value
case ($subkey = "LPT6")
$lpt6 = $value
case ($subkey = "LPT7")
$lpt7 = $value
case ($subkey = "LPT8")
$lpt8 = $value
case ($subkey = "LPT9")
$lpt9 = $value
endselect
endif
endif
$index = $index + 1
$subkey = enumkey($key,$index)
loop

;This resets the MRU Port List by deleting the key and recreating it.
$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\PrnPortsMRU"
$nul = delkey($key)
$nul = addkey($key)

;This reads in the default printer port from the registry.
$DefaultPrinter=readvalue("HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers","Default")

$PrnKey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"
$nul=writevalue($PrnKey,"PrintersMask","00000000",REG_BINARY)
$index = 0
$CurrentPrinter = enumkey($PrnKey,$index)

while (@ERROR = 0)
$FullPrnKey = $PrnKey+"\"+$CurrentPrinter
$CurrentPort = readvalue($FullPrnKey,"Port")

? ? "Current Printer: "+$CurrentPrinter
if ($CurrentPrinter = $DefaultPrinter)
" (default printer)" ?
endif
? " Current Port: "+$CurrentPort

;This translates any captured printer ports to their network port
if (instr($CurrentPort,"LPT") = 1)
select
case (($CurrentPort = "LPT1:") AND ($lpt1 <> 0))
$CurrentPort = $lpt1
case (($CurrentPort = "LPT2:") AND ($lpt2 <> 0))
$CurrentPort = $lpt2
case (($CurrentPort = "LPT3:") AND ($lpt3 <> 0))
$CurrentPort = $lpt3
case (($CurrentPort = "LPT4:") AND ($lpt4 <> 0))
$CurrentPort = $lpt4
case (($CurrentPort = "LPT5:") AND ($lpt5 <> 0))
$CurrentPort = $lpt5
case (($CurrentPort = "LPT6:") AND ($lpt6 <> 0))
$CurrentPort = $lpt6
case (($CurrentPort = "LPT7:") AND ($lpt7 <> 0))
$CurrentPort = $lpt7
case (($CurrentPort = "LPT8:") AND ($lpt8 <> 0))
$CurrentPort = $lpt8
case (($CurrentPort = "LPT9:") AND ($lpt9 <> 0))
$CurrentPort = $lpt9
endselect
" ("+$CurrentPort+")"
endif

if (instr($CurrentPort,"\\") = 0)
? " New Port: Local printer, no port changes needed." ?
else
if (open(10,$prnfile) = 0)
$line = readline(10)
$found = 0
while (@ERROR = 0 and $found = 0)
if (instr($line,";") = 1)
;Ignore semi-colons
endif
if (instr($line,$CurrentPort+",") = 1)
$found = 1
$NewPort = substr($line,instr($line,",")+1,255)
? " New Port: "+$NewPort

;This extracts the name of the old Netware queue name
$templine = substr($CurrentPort,3,255)
$OldQueueName = ucase(substr($templine,instr($templine,"\")+1,255))

;This extracts the name of the new NT queue name
$templine = substr($NewPort,3,255)
$NewQueueName = substr($templine,instr($templine,"\")+1,255)

$nul = writevalue($FullPrnKey,"Port",$NewPort,REG_SZ)
$nul = writevalue($FullPrnKey,"Description",$NewQueueName,REG_SZ)
$nul = writevalue($FullPrnKey,"Attributes","80",REG_DWORD)
$updatedprinters = 1
$nul = writeline(9,$CurrentPrinter+"{F2}"+$NewQueueName+Chr(13)+Chr(10))
endif
$line = readline(10)
loop
$nul=close(10)
if ($found = 0)
color r+/n
? ? "ERROR: Port not found in file: "+$CurrentPort ? ?
color w/n
shell "%comspec% /c pause"
endif
endif ;open(printers.txt)
endif ;$CurrentPort = "\\"
$index = $index + 1
$CurrentPrinter = enumkey($PrnKey,$index)
loop
$nul=close(9)
endif

;This copies the renprn.bat file to the desktop which is a shortcut to the script
;that will rename the printers. This batch file must be run only after the machine
;has been rebooted!! Otherwise, all of the printer ports will be reset to their
;old ones...
if ($updatedprinters = 1)
? ? "Creating printer rename batch on desktop. RUN AFTER REBOOT ONLY!" ? ?
shell "%comspec% /c echo %windir%\kix32.exe "+$scriptpath+"\renprn.kix >%windir%\desktop\RenPrn.bat"
endif
return

----
;======================================================================;
; File........... RENPRN.KIX ;
; Author......... Richard Iglar (richie@iglar.com) ;
; www.isbgroup.com ;
; Description.... Script to aid desktop/laptop migration ;
; Started........ September 15, 2000 ;
; Last Modified.. September 13, 2000 ;
;======================================================================;

:MAIN
break on

;Global variables
$prnrenfile = "%windir%\prnren.txt"
$scriptpath = "w:\msc\scripts\migrate"

;This enlarges the script window to make it more readable
$nul = setconsole("Show")
shell "%comspec% /c mode con: cols=80 lines=43"
$nul = setconsole("Maximize")

if (open(9,$prnrenfile)=0)
? ? "Renaming printers, please wait!!!" ?
run "start "+$scriptpath+"\printers.lnk"
while(setfocus("Printers") <> 0)
sleep 1
loop
sleep 3
$line = readline(9)
while (@ERROR = 0)
$nul = sendkeys($line+"{ENTER}")
sleep 2
$line = readline(9)
loop
$nul = sendkeys("~{F4}")
$nul = close(9)
del $prnrenfile
? ? "Done renaming printers!" ?
else
? "Printer rename file not found!" ?
endif

$key="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce"
$nul=writevalue($key,"DelRenPrn","%comspec% /c del %windir%\desktop\renprn.bat",REG_SZ)
? ? "You may close this window now." ?
exit


----------------

Hopefully the code looks normal, if not I'll post this stuff on a web site somewhere... This code was part of a larger desktop migration script (novell->nt) so there might be some things that dont fit in correctly.


------------------

-Richie