Page 1 of 1 1
Topic Options
#51364 - 2000-09-07 02:32 PM Printer Querrying
Anonymous
Unregistered


Here is a challenge for or ya guys,

We are going to be upgrading our print server from NT 4 to W2k. Our company has about 300 clients (mostly NT) that almost all have several printer connections to this server. After we do the re-install, we will need to remove and then reconnect all of the client printer cunnetions.
I was wondering if there was a way we could set up a login script that will create a list of all current printer connections. Then after the upgrade I could create a script that would reinstall the printers. This would save us a LOT of work.

Thanks

Top
#51365 - 2000-09-07 08:17 PM Re: Printer Querrying
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
mm0015:

I'm going to show my ignorance here, but on first blush, I would assume that if one "upgraded" a Windows NT server to Windows 2000, that the configuration and print share stuff would remain intact.

Are you upgrading or are you performing a wipe and fresh install of Win2K ? (in which case, I can see you're dilema).

Wouldn't there be a migration white paper out there somewhere that addresses this issue ?

Shawn.

[This message has been edited by Shawn (edited 07 September 2000).]

Top
#51366 - 2000-09-07 10:35 PM Re: Printer Querrying
Anonymous
Unregistered


Here is some code that I wrote to migrate printers from an old server to a new server. This scripts assumes a couple things:

* - Only Win95 systems...sorry
* - Print share names must be the same on old and new server.

code:

; ---------- PRINTMIG.KIX ----------------------------------
;
; Created by: Roneil Icatar
; Company: GE Capital IT Solutions
; Date: 4/18/2000
; E-mail: roneil.icatar@gecits.ge.com
; Phone: 860.571.4516
;
; --------------------------------------------------------------
;
; This script is used to migrate users from the old print server
; to the new server. It does this by scanning the correct part
; of the registry and replacing the old server with the new server.
; This script determines the user's servers from the server.txt file
; on the user's PUBLIC share.
;
; ---------- Change Log --------------------------------------
; When Who What
;
;
;
;

IF @INWIN = 1 ;if user is running Windows NT, skip to end
goto end
ENDIF

IF $OPTION = "1"
GOTO INTERACTIVE ; Interactive mode prompts the user for old and new server
ENDIF

;This section reads the servers.txt file from the P drive
;to find the old and new server names
:GETSERVER
IF Open(1,"P:\Migration\Servers.txt",2) = 0
$OLDSERVER = ReadLine(1)
$NEWSERVER = ReadLine(1)
? "Old server is: $OLDSERVER"
? "New server is: $NEWSERVER"
? Close (1)
GOTO CONTINUE
ELSE
GOTO INTERACTIVE ; If the servers.txt file cannot be found, go interactive
ENDIF

:INTERACTIVE
IF $OLDSERVER = ""
? "Enter the old server name: "
GETS $OLDSERVER
ENDIF

IF $NEWSERVER = ""
? "Enter the new server name: "
GETS $NEWSERVER
ENDIF

:CONTINUE
$L = LEN($OLDSERVER)

$HomeKey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"
$index = 0 ; This index is used to count how many printers are installed
$count = 0 ; This count is used to determine how many printers have been changed
:GetKey
$KeyName = EnumKey($HomeKey,$index) ;read the next printer name
if @error = 0
$FullKey = $HomeKey + "\" + $KeyName ;get the full path for the printer registry key
? "Name found: $FullKey"
$Port = READVALUE($FullKey,"Port") ;get the port for current printer
? "Printer port: $Port"
;if the old server name is in the port, replace it with the new server name
if INSTR($PORT,$OLDSERVER)
$Prt = SUBSTR($PORT,$L + 3,99) ;separate the printer share name from the port name
? "Printer name: $Prt"
$NewPort = "\\" + $NEWSERVER + $Prt ;generate new port using new server and printer share
? "New Port will be: $NewPort"
WriteValue($FullKey,"Port",$NewPort,"REG_SZ") ;write this new port to the registry
if @ERROR = 0 ;if successful, write to the log file
OPEN(2,"C:\CHECKAPP\PrintMig.log",5)
WRITELINE(2,"Successfully moved printer " + $Prt + " from " + $OLDSERVER + " to " + $NEWSERVER)
$count = $count + 1 ;increase the count of printers migrated
else
BEEP
? "There was an error redirecting your printers. Please contact the Help Desk."
OPEN(2,"C:\CHECKAPP\PrintMig.log",5)
WRITELINE(2,"Errors while moving printer " + $Prt + " from " + $OLDSERVER + " to " + $NEWSERVER)
endif
endif
$index = $index + 1 ;increment index for next pass
goto GetKey ;loop and read next printer
Endif

:END
; If a printer has been migrated, the user will have to reboot for the change
; to take effect. This section checks to see if the count is greater than 1.
; If so, display a message for the user to reboot their computer.
if $count > 0
? "Please reboot your computer for the changes to take effect."
? "Press any key to continue ..."
get $x
endif
EXIT


Roneil

Top
#51367 - 2000-09-13 09:03 AM Re: Printer Querrying
Anonymous
Unregistered


Can anyone think of a way to migrate the clients.

I found all of the registry keys that I need to change but I can't (KiXtart) RENAME a key.

Any help would be appreciated.

------------------
David Gray
IT Professional
Brisbane Australia

Top
#51368 - 2000-09-13 10:17 AM Re: Printer Querrying
Anonymous
Unregistered


WE've had a lot of fun doing printers (oh yeah) - we replaced our main server for a cluster, and we changed the name from "Main_Server" to "Main-Server". We managed to replace the thing transparent to users and printers was our biggest headache. In the end, we got the part of the registry we needed out, and used GSAR (so-search-and-replace) to make "-" out of "_". Only... somehow, some machines didn't like what we did. I remember during testing that with a wrong script I got a machine to turn off (immediate complete power-down!!!) the instant I loaded the edited registry entries back... [Kids: be carefull with that registry!]

I guess what I'm trying to say is that maybe it isn't such a big deal to have people re-map their printers, which is five minutes for each individual (some may take longer than others *grin*) - as opposed to you having days of gruesome testing to find a solution that probably won't be full-proof.
On the other hand, if you find a solution: Tell me! *hehehe*

I know this wasn't a helpfull post... I'll try to bear better news next time.

Ramon

Top
#51369 - 2000-09-13 03:43 PM Re: Printer Querrying
bUZZeR Offline
Fresh Scripter

Registered: 1999-12-09
Posts: 19
Loc: N-Hamar, Norway
I've found a nice way to delete and install printers via Kix.

IF DelTree("Printers") = 0
?"Connecting valid printers"
else goto error
EndIF

$n=AddPrinterConnection("\\serverX\sharename")
$n=AddPrinterConnection("\\serverX\sharename")
$n=AddPrinterConnection("\\serverX\sharename")
$n=AddPrinterConnection("\\serverX\sharename")
$n=SetDefaultPrinter("Printername")

:Error
?"Unable to remove old printer records, aborted"

The clue is to use DelTree("Printers"), then all the previos information about the network printers are deleted and all printers installed are valid with updated info.

The DelTree("Printers") does NOT affect localprinters !

Hope this helps!

_________________________
Anders Hansen-Øvre http://www.contra.no

Top
#51370 - 2000-09-21 10:19 PM Re: Printer Querrying
Anonymous
Unregistered


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

Top
#51371 - 2000-09-21 10:38 PM Re: Printer Querrying
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Richie to post code and not lose format use

[CODE]
...
.....
.......
[//CODE]*


*Remove the extra /

Bryce

[This message has been edited by Bryce (edited 21 September 2000).]

Top
Page 1 of 1 1


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

Who's Online
0 registered and 867 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.052 seconds in which 0.023 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