Page 1 of 2 12>
Topic Options
#119715 - 2004-05-17 09:55 PM PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Okay, after some searching around the forums, I came up with this:

Code:
 ; -------------------------------------------------------------------
; Call: EnumPrinterConnections()
; Returns: Array of Printers, format is "printer name","printer port name" ; or empty array
; Requires: Windows Script Host 1.0+ (included in IE5.0+)

? "----------------------------------------------------------"

$printers=EnumPrinterConnections()

GOSUB "doUpgrade"

Exit





; ****************************************
;
; SUBROUTINES
;
; ****************************************


:doUpgrade
$DefaultPrinter=ReadValue ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
$oldprintserver="TYPHOON"
$newprintserver="HSCXNTFP0101"
$printers=EnumPrinterConnections()

For Each $printer in $printers
? "Attempting to delete "+$printer+"."
If DelPrinterConnection ("\\"+$oldprintserver+"\"+$printer) = 0
? "Attempting to add "+$printer+"."
If AddPrinterConnection ("\\"+$newprintserver+"\"+$printer) = 0
? $printer+" added successfully."
If InStr ($DefaultPrinter,$printer)
$null = SetDefaultPrinter ("\\"+$newprintserver+"\"+$printer)
Endif
Else
? $printer+" was not added successfully."
Endif
Else
? $printer+" did not need to be deleted."
Endif
?
Next
RETURN









; ****************************************
;
; FUNCTIONS
;
; ****************************************

Function EnumPrinterConnections
; return a list of all printer connections
; format: UNC name, port
Dim $ReturnArray[]
Dim $WshNetwork, $oPrinters
Dim $i

$EnumPrinterConnections=""
$WshNetwork = CreateObject("WScript.Network")
If @Error=0
$oPrinters = $WshNetwork.EnumPrinterConnections
For $i = 0 to $oPrinters.Count-1 Step 2
; init/enlarge the return array
If Ubound($ReturnArray)=-1
ReDim $ReturnArray[0]
Else
ReDim Preserve $ReturnArray[Ubound($ReturnArray)+1]
EndIf
$ReturnArray[Ubound($ReturnArray)]=$oPrinters.Item($i+1)+","+$oPrinters.Item($i)
Next
Else
? "Failed to get WScript.Network object."
EndIf
$EnumPrinterConnections=$ReturnArray
EndFunction




The problem is that it doesn't actually "do" anything. I have several printers on my computer setup that point to Typhoon as the printserver, and they still appear to point to Typhoon now, having run the script several times.

Here's the full result set:


Quote:


----------------------------------------------------------
Attempting to delete \\hscxntfp0101\BA111_1Q,ba111-1q.dhcp.hsc.mb.ca.
\\hscxntfp0101\BA111_1Q,ba111-1q.dhcp.hsc.mb.ca did not need to be deleted.

Attempting to delete \\hscxntfp0101\GC209_1Q,IP_172.16.152.148.
\\hscxntfp0101\GC209_1Q,IP_172.16.152.148 did not need to be deleted.

Attempting to delete \\TYPHOON\BA102_1Q,ba102-1q.dhcp.hsc.mb.ca.
\\TYPHOON\BA102_1Q,ba102-1q.dhcp.hsc.mb.ca did not need to be deleted.




Top
#119716 - 2004-05-17 10:03 PM Re: PrintServer Conversion Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
change this:
Code:

Else
? $printer+" did not need to be deleted."
Endif


to:
Code:

Else
? "\\"+$oldprintserver+"\"+$printer+" did not delete."
? @error @serror
Endif

_________________________
!

download KiXnet

Top
#119717 - 2004-05-17 10:04 PM Re: PrintServer Conversion Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Conversion of Printers?

I have used the following two components with great success here in our company:
Prevent special printers from being deleted

PriMapState() - Checks for existent printerconnection

HTH,

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

Top
#119718 - 2004-05-17 10:48 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Ahhhh...

Code:
 Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>z:

Z:\>kix32.exe typhoonupgrade.kix

----------------------------------------------------------
Attempting to delete \\hscxntfp0101\BA111_1Q,ba111-1q.dhcp.hsc.mb.ca.
\\TYPHOON\\\hscxntfp0101\BA111_1Q,ba111-1q.dhcp.hsc.mb.ca did not delete.

Attempting to delete \\hscxntfp0101\GC209_1Q,IP_172.16.152.148.
\\TYPHOON\\\hscxntfp0101\GC209_1Q,IP_172.16.152.148 did not delete.

Attempting to delete \\TYPHOON\BA102_1Q,ba102-1q.dhcp.hsc.mb.ca.
\\TYPHOON\\\TYPHOON\BA102_1Q,ba102-1q.dhcp.hsc.mb.ca did not delete.

Z:\>



Seems like my base script was completely off. I'll need to rethink this one.

Top
#119719 - 2004-05-17 11:21 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Kent,

I'm not entirely sure how those 2 would solve my issue. I can't do a manual printer=printer mapping, because there are nearly 3000 printers to do.

Hence the server=server type of thing I've written here.

I'm going to plug into my code later, but basically (to me) it seems like I need to rewrite my logic to determine if a printer has "typhoone" as part of it's $printer value. If it does, parse out everything to the right of the last \, delete the printer, and recreate with $newprintserver\[everything to the right of \]...

I'll need to re-examine my code. I was hoping my first shot would work and I wouldn't have to get too deep into parsing strings.

Top
#119720 - 2004-05-18 06:34 AM Re: PrintServer Conversion Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hmmm.. Try this.
Code:

cls
break on
; -- USING IDEAS FROM - http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81569
; -- "Default Printer Configuration"
$reg='HKCU\Software\Microsoft\Windows NT\CurrentVersion'
$dev=$reg+'\Devices'
$nprt=split(READVALUE($reg+'\Windows','Device'),',')[0]
$NEW='HSCXNTFP0101'
$OLD='TYPHOON'
; -- CHECK FOR AND SET THE DEFAULT PRINTER
If $nprt<>''
$srv=SPLIT($nprt,'\')[2] ; SERVER
IF $srv=$old
$prn=SPLIT($nprt,'\')[3] ; PRINTER
$rc=ADDPRINTERCONNECTION('\\'+$new+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
$rc=SETDEFAULTPRINTER('\\'$new+'\'+$prn)
ENDIF
ENDIF
; -- NOW ENUMERATE INSTALLED PRINTERS AND MOVE
$i=0
DO
IF '\\'=LEFT($x,2)
$priReg=$priReg+$x
$srv=SPLIT($dev,'\')[2]
IF $srv=$old
$prn=SPLIT($dev,'\')[3]
$rc=ADDPRINTERCONNECTION('\\'$new+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
ENDIF
ENDIF
$x=ENUMVALUE($dev,$i)
$i=$i+1
UNTIL @error



HTH,

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

Top
#119721 - 2004-05-18 01:11 PM Re: PrintServer Conversion Script
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
Having used PrintMig to move all my printer and associated queues to a new print server a while ago, I needed to repoint all the client printer connections, and also to bear in mind that all the print queues from a number of old servers had been consolidated onto one print server.

It seems that you're trying to do exactly what I did, and this is the code that helped me... (the names have been changed to protect the extremely guilty!)

Code:
$NewPrint = "newprint01"

$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)
$qryPrinters = "select * from win32_printer where servername is not null"
$colPrinters = $objWMI.ExecQuery($qryPrinters)
For Each $objPrinter In $colPrinters
$Name = $objPrinter.ShareName
$Server = $objPrinter.ServerName
$Attr = $objPrinter.Attributes
;? "\\" + $Server + "\" + $Name + " " + $Attr
If $Server = "\\oldprint01" Or "\\oldprint02" Or "\\oldprint03"
$x = DelPrinterConnection($Server + "\" + $Name)
$x = AddPrinterConnection("\\" + $NewPrint + "\" + $Name)
If $Attr & 4
; ? $Name + " is the default printer."
$x = SetDefaultPrinter("\\" + $NewPrint + "\" + $Name)
Endif
Endif
Next
$objWMI = 0



I just added this into my login script, and as users logged in their printer settings were reset. Hope this helps!
_________________________
================================================
Breaker


Top
#119722 - 2004-05-18 03:52 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Breaker,

Yours worked fantastically.

I am actually doing a server merge. How did you get around PrintMig purging the server list on the destination server?

Everytime I try and go from 2 servers to one I find it rather difficult.

Any tips?

As far as the script, yours worked perfectly. I was going to toy with Kent's, as it looked more elegant, but figured I'd try yours.

My question is what OS's are supported by each of these two scripst. Are you using COM in yours (breaker)? How nicely would that play on 9x boxes?

Top
#119723 - 2004-05-18 03:55 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Kent,

I tried your script, but nothing happened. I'm wondering if if isn't something to do with the naming or something...

Thanks again guys

Top
#119724 - 2004-05-18 05:04 PM Re: PrintServer Conversion Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
OK.. OK.. Trying to code from home just doesn't work. That is, there is nothing to test with.

Try this -
Code:
cls
break on
; -- USING IDEAS FROM - http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81569
; -- "Default Printer Configuration"
$reg='HKCU\Software\Microsoft\Windows NT\CurrentVersion'
$dev=$reg+'\Devices'
$nprt=split(READVALUE($reg+'\Windows','Device'),',')[0]
$NEW='HSCXNTFP0101'
$OLD='TYPHOON'
; -- CHECK FOR AND SET THE DEFAULT PRINTER
If $nprt<>''
$srv=SPLIT($nprt,'\')[2] ; SERVER
IF $srv=$old
$prn=SPLIT($nprt,'\')[3] ; PRINTER
$rc=ADDPRINTERCONNECTION('\\'+$new+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
$rc=SETDEFAULTPRINTER('\\'$new+'\'+$prn)
ENDIF
ENDIF
; -- NOW ENUMERATE INSTALLED PRINTERS AND MOVE
$i=0
DO
IF '\\'=LEFT($x,2)
$srv=SPLIT($x,'\')[2]
IF $srv=$old
$prn=SPLIT($x,'\')[3]
$rc=ADDPRINTERCONNECTION('\\'$srv+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
ENDIF
ENDIF
$x=ENUMVALUE($dev,$i)
$i=$i+1
UNTIL @error



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

Top
#119725 - 2004-05-18 05:47 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
So so so close. I really like this solution much better Kent, because it doesn't rely on COM stuff at all.

I just tested it (and added a few +'s you were missing). Here's my code:

Code:
 cls
break on
? "Checking Stuff"
; -- USING IDEAS FROM - http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81569
; -- "Default Printer Configuration"
$reg='HKCU\Software\Microsoft\Windows NT\CurrentVersion'
$dev=$reg+'\Devices'
$nprt=split(READVALUE($reg+'\Windows','Device'),',')[0]
$NEW='HSCXNTFP0101'
$OLD='TYPHOON'
; -- CHECK FOR AND SET THE DEFAULT PRINTER
If $nprt<>''
$srv=SPLIT($nprt,'\')[2] ; SERVER
IF $srv=$old
$prn=SPLIT($nprt,'\')[3] ; PRINTER
$rc=ADDPRINTERCONNECTION('\\'+$new+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
$rc=SETDEFAULTPRINTER('\\'+$new+'\'+$prn)
ENDIF
ENDIF
; -- NOW ENUMERATE INSTALLED PRINTERS AND MOVE
$i=0
DO
IF '\\'=LEFT($x,2)
$srv=SPLIT($x,'\')[2]
IF $srv=$old
$prn=SPLIT($x,'\')[3]
$rc=ADDPRINTERCONNECTION('\\'+$srv+'\'+$prn)
$rc=DELPRINTERCONNECTION('\\'+$srv+'\'+$prn)
ENDIF
ENDIF
$x=ENUMVALUE($dev,$i)
$i=$i+1
UNTIL @error

? "Done"

EXIT



The problem is that if I setup 2 printers on the old server. 1 as default, the other not. Only the default one gets moved (though it IS reassigned as default, which is great!). The other simply gets deleted.

I was going to step through your code, but I figured you knew it better than I did. I don't mind debugging it if you're too busy though ;-)

Top
#119726 - 2004-05-18 09:26 PM Re: PrintServer Conversion Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Please help yourself in debugging, cleaning, and distilling down the code. I am in the middle of a database conversion, migration and various sundry tasks.

The one thing I do ask is when you get the final script, to post the results here.

You may have to add a couple of sleep statements..

Kent


Edited by kdyer (2004-05-18 09:26 PM)
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#119727 - 2004-05-18 09:37 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Fair enough, thanks for your help thus far, it helps immensely!
Top
#119728 - 2004-05-19 11:22 AM Re: PrintServer Conversion Script
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
Errr... strangely enough, I don't recall having had any problems merging the print queues from my old servers onto the new one. Can't really help you there, I'm afraid, though I'll do a little digging this morning if I get a chance.

As far as the COM stuff goes, yeah, this scriptlet uses WMI to read the existing printer configuration, which means that WMI needs to be available on the client machine. If you've got Win2k or XP then you've got WMI. However, if you're running NT or (god forbid) 9x, then you'll need to install WMI. You can download it from here-

Windows Management Instrumentation (WMI) CORE 1.5 (Windows 95/98/NT 4.0)

But then you need to install it on your 9x machines, some of them may also require the DCOM installation, that requires an upgrade to IE, etc, etc.

I agree, Kent's method certainly has less dependencies. Good luck however you choose to do it.
_________________________
================================================
Breaker


Top
#119729 - 2004-05-19 03:31 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Breaker,

We're a hospital. 5000 desktops, 700 of which are 9x machines, so yeah it's gotta work on those.

Most of the KiX stuff I do is (thankfully) only for the up-level PC's.

I still haven't figured out why Kent's isn't working, but I'll get there ;-)

Thanks again for your help

Top
#119730 - 2004-05-19 03:43 PM Re: PrintServer Conversion Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I did a printer server clustering script at 1999 for one hospital (clients little less, around 2000) and it worked fine.
although, I remember something about my script was not liked on win9x users.
but, doesn't matter, as win9x was not liked either

dropping support for it will drop it off.
leaving support, will make the administering a pain.
_________________________
!

download KiXnet

Top
#119731 - 2004-05-19 04:30 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Oh, at the end of the year all 95 boxes will be unplugged, and next summer all 98 boxes will. It's just not the kind of change that can be done quickly in an organization like this

So we'll definitely get ther, in the meantime I need to write scripts that will also work on them ;-)

Top
#119732 - 2004-05-19 04:59 PM Re: PrintServer Conversion Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well...
maybe you don't see the options but...
saying to boss, it's not possible in win9x on each turn makes them disappear in a month or 2.
believe me
I have some experience there :P
_________________________
!

download KiXnet

Top
#119733 - 2004-05-19 05:05 PM Re: PrintServer Conversion Script
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Jeremy, I have a script that I used in production for a print server move. The caveat with this function is that only the print server name is changing, not the print queue itself. For the 9x PCs it just resets the network path in the settings, so the PCs must be rebooted before they will be able to print. Give it a go and see if it helps...

Code:

Function fnRemapPrinters($sOldServer,$sNewServer)
Dim $lIndex,$sPorts,$sServer,$sPrinter,$sPort,$sSplit,$lS,$sShare,$NUL,$Err,$sDevice,$sDefault,$sPrinterPorts
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]
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")
If SUBSTR($sServer,3,LEN($sServer))=$sOldServer
$sPrinter=Split($sPrinters[$lIndex],",")[3]
$NUL=AddPrinterConnection("\\"+$sNewServer+"\"+$sPrinter)
If @ERROR
$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")
$sSplit=Split($sPort,"\")
If $sSplit[2]=$sOldServer
$lS=Len($sPort)-Len($sOldServer)-2
$sShare=Right($sPort,$lS)
$NUL=WriteValue($sPorts+$sPrinters,"Port","\\"+$sNewserver+$sShare,"REG_SZ")
If @ERROR $Err=@ERROR EndIf
$sDevice=ReadProfileString ("Win.ini", "Windows", "Device")
$sDevice=Split($sDevice,",")
If $sDevice[2]=$sPort
$NUL=WriteProfileString ("Win.ini", "Windows", "Device",
$sDevice[0]+","+$sDevice[1]+","+"\\"+$sNewserver+$sShare)
If @ERROR $Err=@ERROR EndIf
EndIf
$NUL=WriteProfileString ("Win.ini", "Ports", $sPort)
$NUL=WriteProfileString ("Win.ini", "Ports", "\\"+$sNewserver+$sShare, " ")
If @ERROR $Err=@ERROR EndIf
$sPrinterPorts=ReadProfileString ("Win.ini", "PrinterPorts", $sPrinters)
$sPrinterPorts=Split($sPrinterPorts,",")
$NUL=WriteProfileString ("Win.ini", "PrinterPorts", $sPrinters,
$sPrinterPorts[0]+","+"\\"+$sNewserver+$sShare+","+$sPrinterPorts[2]+","+$sPrinterPorts[3])
If @ERROR $Err=@ERROR EndIf
$sDevices=ReadProfileString ("Win.ini", "Devices", $sPrinters)
$sDevices=Split($sDevices,",")
$NUL=WriteProfileString ("Win.ini", "Devices", $sPrinters, $sDevices[0]+","+"\\"+$sNewserver+$sShare)
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


Top
#119734 - 2004-05-19 10:58 PM Re: PrintServer Conversion Script
jeremywright Offline
Fresh Scripter

Registered: 2004-04-21
Posts: 20
Loc: Canada
Chris,

Wow, that's perfect. I've tested it on half a dozen workstations, and I've been modifying it slightly for our production environment (logging and so on).

Thanks a bunch to everyone who helped out

Top
Page 1 of 2 12>


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

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

Generated in 0.108 seconds in which 0.032 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