Page 1 of 1 1
Topic Options
#45199 - 2003-09-15 09:52 PM Change Print Server
leno Offline
Fresh Scripter

Registered: 2002-09-18
Posts: 30
I have NT4 with 30 printers serving 200 users. i want to replace the server. i installed the printers on another NT4 server. i would like to find a quick way to change the user printer path to the new server. any ideas ?
Top
#45200 - 2003-09-15 10:19 PM Re: Change Print Server
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here's something I ran in our environment when we migrated print servers. It ran with a lot of success. Includes methods for redirecting network printers on 9x machines too.

Below is the test script I ran before integrating it in the login script...

code:
Break On CLS

Dim $,$ticks,$rc

$ticks=@ticks
$rc = fnRemapPrinters("old_server","new_server")
;$rc = fnRemapPrinters("new_server","old_server")
? @ERROR ":" @SERROR

?? "Remapped "+ $rc + " Printers in "+(@ticks-$ticks)/1000+" seconds."
?? "Press any key to exit."
Get $

If @INWIN=2 and $RC
$nul=MESSAGEBOX ("Your settings have been changed. A reboot is required", "Relizon", 0)
RUN "%WINDIR%\RUNDLL32.EXE SHELL32.DLL,SHExitWindowsEx 2"
RUN "%WINDIR%\RUNDLL32.EXE USER.EXE,ExitWindowsExec"
EndIf
get $
Exit 1


Function fnRemapPrinters($sOldServer,$sNewServer)
Dim $lIndex,$NUL,$Err,$sDefault,$sDevice,$sDevices,$sPort,$sPorts,$sPrinter,$sPrinterPorts,$sServer
Dim $sPrinters[100]
$fnRemapPrinters=0
$lIndex=0
If @INWIN=1
$sPorts="HKCU\Printers\Connections\"
$sDefault=Split(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]
;"Installed Printers:" ?? ; Debug
Do
$sPrinters[$lIndex]=EnumKey($sPorts,$lIndex)
$lIndex=$lIndex+1
If Ubound($sPrinters)=$lIndex Redim Preserve $sPrinters[Ubound($sPrinters)+100] EndIf
Until @ERROR
Redim Preserve $sPrinters[$lIndex-1]
For $lIndex = 0 to Ubound($sPrinters)
$sServer=ReadValue($sPorts+$sPrinters[$lIndex],"Server")
;"Printer: "+$sPrinters[$lIndex]+" Server: "+$sServer ? ; Debug: Lists installed network printers.
If SUBSTR($sServer,3,LEN($sServer))=$sOldServer
$sPrinter=Split($sPrinters[$lIndex],",")[3]
$NUL=AddPrinterConnection("\\"+$sNewServer+"\"+$sPrinter)
If @ERROR
;"AddPrinterConnection Failed: "+@ERROR" : "+@SERROR ; Debug: Printers error msg
$Err=@ERROR
Else
If $sDefault="\\"+$sOldServer+"\"+$sPrinter
$NUL=SetDefaultPrinter("\\"+$sNewServer+"\"+$sPrinter)
EndIf
$NUL=DelPrinterConnection("\\"+$sOldServer+"\"+$sPrinter)
If @ERROR $Err=@ERROR EndIf
$fnRemapPrinters=$fnRemapPrinters+1
EndIf
EndIf
Next
Else
$sPorts="HKLM\System\CurrentControlSet\control\Print\Printers\"
Do
$sPrinters=EnumKey($sPorts,$lIndex)
If $sPrinters
$sPort=ReadValue($sPorts+$sPrinters,"Port")
If Split($sPort,"\")[2]=$sOldServer
$sPrinter=Right($sPort,Len($sPort)-Len($sOldServer)-2)
$NUL=WriteValue($sPorts+$sPrinters,"Port","\\"+$sNewserver+$sPrinter,"REG_SZ")
If @ERROR $Err=@ERROR EndIf
$sDevice=Split(ReadProfileString("Win.ini","Windows","Device"),",")
If $sDevice[2]=$sPort
$NUL=WriteProfileString("Win.ini","Windows","Device",
$sDevice[0]+","+$sDevice[1]+","+"\\"+$sNewserver+$sPrinter)
If @ERROR $Err=@ERROR EndIf
EndIf
$NUL=WriteProfileString("Win.ini","Ports",$sPort)
$NUL=WriteProfileString("Win.ini","Ports","\\"+$sNewserver+$sPrinter," ")
If @ERROR $Err=@ERROR EndIf
$sPrinterPorts=Split(ReadProfileString("Win.ini","PrinterPorts",$sPrinters),",")
$NUL=WriteProfileString("Win.ini","PrinterPorts",$sPrinters,
$sPrinterPorts[0]+","+"\\"+$sNewserver+$sPrinter+","+$sPrinterPorts[2]+","+$sPrinterPorts[3])
If @ERROR $Err=@ERROR EndIf
$sDevices=Split(ReadProfileString("Win.ini","Devices",$sPrinters),",")
$NUL=WriteProfileString("Win.ini","Devices",$sPrinters,$sDevices[0]+","+"\\"+$sNewserver+$sPrinter)
If @ERROR $Err=@ERROR EndIf
If Not $Err $fnRemapPrinters=$fnRemapPrinters+1 EndIf
EndIf
EndIf
$lIndex=$lIndex+1
Until $sPrinters=""
EndIf
If Not $Err $Err=0 EndIf
Exit $Err
EndFunction



[ 15. September 2003, 22:20: Message edited by: Chris S. ]

Top
#45201 - 2003-09-22 08:58 AM Re: Change Print Server
leno Offline
Fresh Scripter

Registered: 2002-09-18
Posts: 30
Thanks,
It works great for me too.

Leno

Top
#45202 - 2003-09-23 12:27 AM Re: Change Print Server
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
With complements to Jens!

code:
  


;**** Dit script wijzigd de naam van de printserver van prtsrv01 naar prtsrv02 ****
;**** Last Modified on 20-08-2003 at 11:52:44 AM by Co****


Break on
If @producttype = 'Windows XP Professional'

Dim $printers, $printer, $rc

$printers=arrayenumkey('HKCU\Printers\Connections')

For Each $printer In $printers
If InStr($printer,'prtsrv01')
$printer=Split($printer,',')
$old='\\'+$printer[2]+'\'+$printer[3]
$new="\\prtsrv02\" + $printer[3]
? '-I- Connection found: '+$old
$rc=DelPrinterConnection($old)
If @error
? '-E- Error deleting connection to '+$old+' (EC='+@error+')'
Else
? '-I- Succesfully deleted connection to '+$old
EndIf

$rc=AddPrinterConnection($new)
If @ERROR
? '-E- Error connecting to '+$new+' (EC='+@error+')'
Else
? '-I- Succesfully added connection to '+$new
EndIf
EndIf

;Exit

;FUNCTION
;
;NAME ArrayEnumKey
;
;ACTION Creates an array of names of the subkeys contained in a registry key or subkey
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.2 (added error codes)
; 1.1
;
;DATE CREATED 2001/12/05
;
;DATE MODIFIED 2003/05/17
;
;KIXTART 4.12+
;
;SYNTAX ARRAYENUMKEY($subkey)
;
;PARAMETERS SUBKEY
; Required string containing the key or subkey for which the subkeys will be enumerated
;
;RETURNS Array containing the subkeys
;
;REMARKS none
;
;DEPENDENCIES none
;
;EXAMPLE $retcode=arrayenumkey('HKEY_USERS')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000064
;
Function arrayenumkey($regsubkey)
Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray

If NOT KeyExist($regsubkey)
Exit 87
EndIf

$subkeycounter=0
Do
$currentsubkey=EnumKey($regsubkey,$subkeycounter)
If NOT @ERROR
ReDim preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
EndIf
Until @ERROR

$arrayenumkey=$subkeyarray
Exit 0
EndFunction

_________________________
Co


Top
#45203 - 2003-09-23 12:31 AM Re: Change Print Server
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
co, your script does not work on win9x, right?
_________________________
!

download KiXnet

Top
#45204 - 2003-09-22 08:26 PM Re: Change Print Server
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
Ja, you're right... Because of the add/delprinterconnection..
_________________________
Co


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.063 seconds in which 0.033 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