Page 1 of 1 1
Topic Options
#14249 - 2001-11-14 05:15 AM remapping printer shares
Patriot Offline
Lurker

Registered: 2001-11-14
Posts: 2
Loc: San Antonio
I am replacing a WINNT 4.0 printer server with another WINNT 4.0 print server, I know how to migrate the printers and drivers, I need help creating a script that will point the workstations, over 300 of which 95% are still on WIN95, the rest on WINNT workstation, to the new printer shares. Thanks in advance.
Top
#14250 - 2001-11-15 05:40 AM Re: remapping printer shares
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Welcome to the board.

In an old topic we found a solution for your W9x environment.
See topic
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=001106
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#14251 - 2001-11-15 04:55 PM Re: remapping printer shares
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
Patriot -
This may work for you.
Bill

code:

; rem
:Change_Printer
; rem #################################################################
; rem ## Emergency printer port change for when server is down. ##
; rem ## Process is dynamic, no systems will require reboot. ##
; rem ## ##
; rem ## Process built as 'hot' cutover to print server with ##
; rem ## defined printers AND shares named EXACTLY as primary ##
; rem ## server, and printers already configured on client. ##
; rem ## ##
; rem ## !! DOES NOT CONFIRM PRINTER DRIVERS INSTALLED, ETC. !! ##
; rem ## ##
; rem #################################################################


; REM ** Variable in use by this script
DIM $Alpha, $Count, $CurPrn, $CurSvr, $LenPrn, $LenSvr, $NewPort, $NewPrnKey, $NewSvr
DIM $OldPort, $OldPrnKey, $OldSvr, $RegKey


$OldSvr = "XYZ987" $NewSvr = "ABC123" $Alpha = "Backward"
; $OldSvr = "ABC123" $NewSvr = "XYZ987" $Alpha = "Forward"


SELECT
CASE (@INWIN = 1)
; REM ** Index tracker - increments or decrements depending upon alpha-numeric naming of servers.
; REM ** Failure to decrement will mean some print devices skipped as index values change with rename process.
$HKEY = ("HKEY_CURRENT_USER\Printers\Connections")
SELECT
CASE ($Alpha = "Forward")
$Count = -1
WHILE (@ERROR = 0)
$Count = $Count + 1
$OldPrnKey = ENUMKEY ($HKEY, $Count)
LOOP
$x1 = ($Count-1)
CASE (1) $x1 = 0
ENDSELECT


; REM ** Find the printer key, check if matches 'current' printer, and the values associated with the key.
; REM ** After finding values of the key, delete old key and write new key and values if do not already exist.


:LOOP_NT_Printer
$OldPrnKey = ENUMKEY ($HKEY, $x1)
IF (@ERROR = 0)
; REM ** Parse port name and printer name to variables
$LenPrn = LEN ($OldPrnKey)
$LenSvr = LEN ($OldSvr)
$CurPrn = SUBSTR ($OldPrnKey, (($LenSvr)+4), $LenPrn)
$CurSvr = SUBSTR ($OldPrnKey, 3, ($LenPrn - ((LEN ($CurPrn) +3 ))))
$RegKey = ($HKEY + "\" + $OldPrnKey)
IF ($CurSvr <> $NewSvr)
DIM $RegVal[20] ; REM ** Variable count of 20 printers arbitrary - my system only had 3 keys.
DIM $RegSet[20]
DIM $RegTyp[20]
$x2 = 0 ; REM ** Index to loop through value entries for each subkey/printer
:LOOP_PrnVal
$RegVal[$x2] = ENUMVALUE ($RegKey, $x2)
SELECT
CASE (@ERROR = 0)
$RegSet[$x2] = READVALUE ($RegKey, $RegVal[$x2])
$RegTyp[$x2] = READTYPE ($RegKey, $RegVal[$x2])
IF ($RegSet[$x2] = "\\" + $OldSvr) $RegSet[$x2] = "\\" + $NewSvr ENDIF
$x2 = $x2+1
GOTO LOOP_PrnVal
CASE (1)
DELKEY ($RegKey)
IF (@ERROR = 0) $Mgg = "Success"
ELSE $Msg = "Error @ERROR"
ENDIF
$wri = WRITELINE (1, "$Msg deleting Printer registry key: $RegKey" + $CR)
$NewPrnKey = ($HKEY + "\,," + $NewSvr + "," + $CurPrn)
$RC = EXISTKEY ($NewPrnKey) ; REM ** Only make key if does not exist
IF (@ERROR = 0)
$wri = WRITELINE (1, "Printer registry key already exists: $NewPrnKey" + $CR)
ELSE
ADDKEY ($NewPrnKey)
IF (@ERROR = 0) $Msg = "Success"
ELSE $Err = $Err+1 $Msg = "Error @ERROR"
ENDIF
$wri = WRITELINE (1, "$Msg adding Printer registry key: $NewPrnKey" + $CR)
$x3 = 0 ; REM ** Index to match with value entry count from above
WHILE ($x3 < $x2)
$wri = WRITEVALUE ("$NewPrnKey", $RegVal[$x3], $RegSet[$x3], $RegTyp[$x3])
IF (@ERROR = 0) $x3 = $x3+1 $Msg = "Success"
ELSE $Err = $Err+1 $Msg = "Error @ERROR"
ENDIF
$wri = WRITELINE (1, "$Msg writing Printer value: $NewPrnKey, " + $RegSet[$x3] + $CR)
LOOP
ENDIF
ENDSELECT
ENDIF


SELECT
CASE ($Alpha = "Forward") $x1 = $x1-1
CASE (1) $x1 = $x1+1
ENDSELECT
GOTO LOOP_NT_Printer
ENDIF


CASE (1)
$HKEY = ("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers")
$x1 = 0
:LOOP_Win9X_Printer
$OldPrnKey = ENUMKEY ($HKEY, $x1)
$RegKey = ($HKEY + "\" + $OldPrnKey)
$OldPort = READVALUE ($RegKey, "Port")
IF (@ERROR = 0)
$LenPrn = LEN ($OldPort)
$LenSvr = LEN ($OldSvr)
$CurPrn = SUBSTR ($OldPort, (($LenSvr)+4), $LenPrn)
$CurSvr = SUBSTR ($OldPort, 3, ($LenPrn - ((LEN ($CurPrn) +3 ))))
$NewPort = "\\" + $NewSvr + "\" + $CurPrn
IF ($CurSvr = $NewSvr)
$wri = WRITELINE (1, "Printer registry key already exists: $NewPrnKey" + $CR)
ELSE
$wri = WRITEVALUE ("$RegKey", "Port", $NewPort, "REG_SZ")
IF (@ERROR = 0) $Msg = "Success"
ELSE $Err = $Err+1 $Msg = "Error @ERROR"
ENDIF
$wri = WRITELINE (1, "$Msg adding Print registry key: $NewPrnKey, $NewPort" + $CR)
ENDIF
$x1 = $x1+1
GOTO LOOP_Win9X_Printer
ENDIF
ENDSELECT
RETURN



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.101 seconds in which 0.069 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org