Page 1 of 1 1
Topic Options
#142996 - 2005-07-05 04:17 PM Migrating printers
jvanelst Offline
Lurker

Registered: 2005-05-18
Posts: 3
Hi,

We have about 50 printers, and 2 printservers. I am wondering how we can migrate the printers on the user desktops (about 1000 desktops) to the new printservers using a .ini file. can somebody get me started with this.

Regards

Jeroen

Top
#142997 - 2005-07-05 04:33 PM Re: Migrating printers
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you want to "migrate" as in remove either one of those servers?
_________________________
!

download KiXnet

Top
#142998 - 2005-07-06 12:00 AM Re: Migrating printers
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Check this post out.. We have used it many times with great success - Prevent special printers from being deleted

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#142999 - 2005-07-07 09:59 AM Re: Migrating printers
jvanelst Offline
Lurker

Registered: 2005-05-18
Posts: 3
Thanks for replying,

the problem is that i cannot remove all the printers that are configured on the machines, i want to do the following steps.

1. Read the type of printer from the registry
2. configure the printer, that uses the new printserver.
3. remove the old connection.

I made this script, but this is only for one printer. We have about 50 printers, that means i need a script of 400 lines.

$printerpath = "HKEY_CURRENT_USER\Printers\Connections"
$hp4050 = ReadValue ("$printerpath\,,oldserver,HP4050","Server")
IF $hp4050="oldserver"
ADDPRINTERCONNECTION ("\\newserver\hp4050")
DELKEY ("$printerpath\,,oldserver,hp4050")
ENDIF

Thanks

Top
#143000 - 2005-07-07 10:07 AM Re: Migrating printers
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you only need to change the print server name there are scripts already written on the board which will do this for you - I know because I posted one a long time ago.

If you need to re-connect the printers to pick up new printer drivers then you should be able to kludge the script to do this for you with very little additional effort.

Search the board for the scripts - if you get stuck and really cannot find them then post again and we'll have a look for you.

Top
#143001 - 2005-07-07 10:35 AM Re: Migrating printers
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I had trouble finding the old posts.

Here's an (untested) version of one I've used in-house.

I say untested because I've had to remove a load of stuff to do with changing share names on the fly.

You will need to change the values of the variables $sLogFilePath, $sOldServer and $sNewServer.

Code:
Break ON
$gNull=SetOption("Explicit","ON")
$gNull=SetOption("ASCII","ON")
$gNull=SetOption("WrapAtEOL","ON")

Global $sLogFilePath

Dim $sDelimiter
Dim $sOldServer,$sNewServer
Dim $sOldPrefix,$sNewPrefix,$sNulPrefix
Dim $sDefaultPrinterKey,$sDefaultPrinterEntry,$sPrinters
Dim $iIndex
Dim $sPrinterKey,$sPrinterServer,$sPrinterShare

Dim $sPrintersToMove,$sPrintersToAdd
Dim $sDefaultPrinter

; Array seperator
$sDelimiter="|"

; Log file path - set to null to disable logging to a file.
$sLogFilePath=@HOMESHR+"\"+"PrinterMove.log"

; Print server definitions.
$sOldServer="OLDSERVERNAME"
$sNewServer="NEWSERVERNAME"

; Printer registry keys
$sDefaultPrinterKey="HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$sDefaultPrinterEntry="Device"
$sPrinters="HKCU\Printers\Connections"

; Get default printer information
$sDefaultPrinter=Split(ReadValue($sDefaultPrinterKey,$sDefaultPrinterEntry),",")[0]
$sPrinterServer=Split($sDefaultPrinter,"\")[2]
$sDefaultPrinter=Split($sDefaultPrinter,"\")[3]

$iIndex=0
$sPrinterKey=EnumKey($sPrinters,$iIndex)
While Not @ERROR
$sPrinterServer=Split($sPrinterKey,",")[2]
$sPrinterShare=Split($sPrinterKey,",")[3]
Select
Case $sPrinterServer=$sNewServer
; No action required
Case $sPrinterServer=$sOldServer
$sPrintersToMove=$sPrintersToMove+$sDelimiter+$sPrinterShare
Case "UnknownPrintServer"
udfLog("WARNING: Print server "+$sPrinterServer+" not recognised for printer "+$sPrinterName)
EndSelect
$iIndex=$iIndex+1
$sPrinterKey=EnumKey($sPrinters,$iIndex)
Loop

; Delete printers being moved.
For Each $sPrinterShare In Split($sPrintersToMove,$sDelimiter)
If $sPrinterShare
If DelPrinterConnection("\\"+$sOldServer+"\"+$sPrinterShare)
udfLog("Error "+@ERROR+" deleting printer "+"\\"+$sOldServer+"\"+$sPrinterShare)
Else
udfLog("Printer "+"\\"+$sOldServer+"\"+$sPrinterShare+" deleted OK")
EndIf
EndIf
Next

; Add printers at new destination.
For Each $sPrinterShare In Split($sPrintersToMove,$sDelimiter)
If $sPrinterShare
If AddPrinterConnection("\\"+$sNewServer+"\"+$sPrinterShare)
udfLog("Error "+@ERROR+" connecting printer \\"+$sNewServer+"\"+$sPrinterShare)
Else
udfLog("Printer \\"+$sNewServer+"\"+$sPrinterShare+" connected OK")
; Set up default printer
If $sDefaultPrinter=$sPrinterShare
If SetDefaultPrinter("\\"+$sNewServer+"\"+$sPrinterShare)
udfLog("Error "+@ERROR+" setting default printer \\"+$sNewServer+"\"+$sPrinterShare)
Else
udfLog("Printer \\"+$sNewServer+"\"+$sPrinterShare+" set as default OK")
EndIf
EndIf
EndIf
EndIf
Next


Exit 1

; Log changes and errors.
Function udfLog($sMessage)
$sMessage=@DATE+" "+@TIME+" ["+@WKSTA+"] "+$sMessage+@CRLF
$sMessage
If $sLogFilePath
Dim $fh
$fh=FreeFileHandle()
If Open($sLogFilePath,1+4)
"**ERROR** Cannot open log file "+$sLogFilePath+" for writing!"+@CRLF
Else
$gNull=WriteLine($fh,$sMessage)
$gNull=Close($fh)
EndIf
EndIf
EndFunction
; vim600:ts=3 sw=3


Top
#143002 - 2005-07-07 11:55 AM Re: Migrating printers
jvanelst Offline
Lurker

Registered: 2005-05-18
Posts: 3
Thanks Richard, This script works great for us.

Many many many thanks.

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.066 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