By the way, here is the code that works...

code:

;
; This script is called from the logon script. It will remove all the network
; printers that have been added, then it will add the printers needed for the
; workstation that the user is logging into.
;
; Pat Hennessy - 2/16/2001
;

;
; Delete all network printers.
;
:del_printer_loop

$pinfo = enumkey("HKEY_CURRENT_USER\Printers\Connections\", 0)
if (@error = 0)
$pconnection = ""
$index = 1
do
$letter = substr($pinfo, $index, 1)
if ($letter = ",")
$pconnection = $pconnection + "\"
else
$pconnection = $pconnection + $letter
endif
$index = $index + 1
until ($index = len($pinfo) + 1)
if delprinterconnection($pconnection)
$return = messagebox("An error occurred while removing $pconnection.", "Error removing printer (@error)", 4096 + 16)
endif
goto del_printer_loop
endif

;
; Delete old HKCU registry stuff
;
if (existkey("HKEY_CURRENT_USER\Software\DTCC") = 0)
$return = deltree("HKEY_CURRENT_USER\Software\DTCC")
endif

;
; Next we see if this workstation uses a windows print server.
;
if (existkey("HKEY_LOCAL_MACHINE\SOFTWARE\DTCC\Printing") = 0)
gosub "ntprint"
exit 0
else
exit 1
endif

;
; Thats all folks (except for the subroutine below)
;
exit 0

;
; Start of ntprint subroutine.
;
:ntprint

;
; Now we need to find and add the local printers.
;
$index = 0

:add_printer_loop

$val_name = enumvalue("HKEY_LOCAL_MACHINE\SOFTWARE\DTCC\Printing\Local Printers", $index)
if (@error = 0)
$new_printer = readvalue("HKEY_LOCAL_MACHINE\SOFTWARE\DTCC\Printing\Local Printers", $val_name)
if (addprinterconnection($new_printer))
$return = messagebox("An error occurred while adding $new_printer.", "Error adding printer (@error)", 4096 + 16)
else
if (substr($new_printer, 13, 2) = "pl")
use lpt3: /del
use lpt3: "$new_printer"
if (@error > 0)
$return = messagebox("An error occurred while setting lpt3: to $new_printer.", "Error adding printer (@error)", 4096 + 16)
endif
endif
endif
$index = $index + 1
goto add_printer_loop
endif

;
; Next we need to determine the default printer.
;
$default_printer = readvalue("HKEY_LOCAL_MACHINE\SOFTWARE\DTCC\Printing", "Default Printer")

if (@error = 0)
if (setdefaultprinter($default_printer))
$return = messagebox("An error occurred while setting the default printer to $default_printer.", "Error setting default printer (@error)", 4096 + 16)
endif
if (substr($default_printer, 1, 2) = "\\")
use lpt2: /del
use lpt2: "$default_printer"
if (@error > 0)
$return = messagebox("An error occurred while setting lpt2: to $default_printer.", "Error setting default printer (@error)", 4096 + 16)
endif
endif
endif

; End of ntprint subroutine.
return