wk2x
(Fresh Scripter)
2005-11-01 03:49 PM
!IMPORTANT! Printmigration

Hello People

I have a big Problem with the Printmigration

I have 150 Printers and now i will change my Printserver.
The old Printer's call homeprinter1, homeprinter2...The new nameconversation is now printer1, printer2....
So i have make a Script:
-------------------------------------------------------
If DelPrinterConnection ("\\server1\homeprinter1") = 0
AddPrinterConnection ("\\server4\printer1")
EndIf
.
.
.
.
.
-------------------------------------------------------

That's function good, but the the loginscript using a long time to running because they are so much printers...

Have you got anothter solution??? It's very important for me.

best regards
wk2x

PS: Thank you for your help


LonkeroAdministrator
(KiX Master Guru)
2005-11-01 05:24 PM
Re: !IMPORTANT! Printmigration

you should use either a enumConnectedPrinters() or loop via all of the possible printers with isPrinterConnected()

hmm...
I think the easier would be the first choice.
damn, actually, I see that there is only wsh dependant udf's on that section

can you give an example of a value in:
HKEY_CURRENT_USER\Printers\Connections

asking this cause I don't currently have access to any network nor networked printers to write the script for you


Chris S.
(MM club member)
2005-11-01 05:27 PM
Re: !IMPORTANT! Printmigration

Here is a function that I use to remap printers...

Code:

Function fnRemapPrinter($sOldPath,$sNewPath)
Dim $i,$nul,$sPorts,$sDefault,$sPrinters[25]
If @INWIN=1
$sPorts="HKCU\Printers\Connections\"
$sDefault=Split(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]
Do
$sPrinters[$i]=EnumKey($sPorts,$i)
$i=$i+1
If Ubound($sPrinters)=$i Redim Preserve $sPrinters[Ubound($sPrinters)+25] EndIf
Until @ERROR
Redim Preserve $sPrinters[$i-1]
For $i = 0 to Ubound($sPrinters)
If Join(Split($sPrinters[$i],","),"\") = $sOldPath
$nul = DelPrinterConnection($sOldPath)
$nul = AddPrinterConnection($sNewPath)
If $sDefault = $sOldPath
$nul = SetDefaultPrinter($sNewPath)
EndIf
EndIf
Next
EndIf
Exit @ERROR
EndFunction



wk2x
(Fresh Scripter)
2005-11-01 05:44 PM
Re: !IMPORTANT! Printmigration

yes, i can.
HKEY_CURRENT_USER -> Connections > ,,server1,homeprinter1

and in this Section are Server with the Value \\server1


wk2x
(Fresh Scripter)
2005-11-01 05:46 PM
Re: !IMPORTANT! Printmigration

Thank you for your help, but when i testing your script....
they Printers aren't make anything


LonkeroAdministrator
(KiX Master Guru)
2005-11-01 06:39 PM
Re: !IMPORTANT! Printmigration

hmm...
if you wanna move all printers from one server to another call the above function with the servernames and change this line:
Code:

If Join(Split($sPrinters[$i],","),"\") = $sOldPath



to:
Code:

If instr($sPrinters[$i],",,"+$sOldPath+",")



wk2x
(Fresh Scripter)
2005-11-01 06:54 PM
Re: !IMPORTANT! Printmigration

ohhh, no i think you understand me false.
I have a 2 Printservers an old and a new.
The Old Printers are all again installed on the new Server.
But the Client's use still the old Server. So i need a script for the clients
that running fast and add the printer they are installed on the clients again. Naturally from the new Server with the new naming convention.
Do you know what i mean?


Kdyer
(KiX Supporter)
2005-11-01 07:00 PM
Re: !IMPORTANT! Printmigration

The PriMapState should be all that you need..

PriMapState() - Checks for existent printerconnection

We have used it many times with printers being moved around to other servers and it works great!

Kent


wk2x
(Fresh Scripter)
2005-11-01 07:12 PM
Re: !IMPORTANT! Printmigration

hmmm..interesting... have you got an example from a move script...sorry, i don't
understanding this script...


NTDOCAdministrator
(KiX Master)
2005-11-01 07:20 PM
Re: !IMPORTANT! Printmigration

Right here in the EXAMPLES forum is an example.


Move Printer Server
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=118702

This came from a post that started here. Take the time to read the post and you should see how easy it is to change the clients to a new print server.

Prevent special printers from being deleted
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB1&Number=37277
 


LonkeroAdministrator
(KiX Master Guru)
2005-11-01 07:54 PM
Re: !IMPORTANT! Printmigration

noooooooo!

wk2x, I understood you 100%.
you just didn't get me.

you need to add the given code to your logonscript and it does exactly what you asked.

and, like I already said in the beginning, primapstate() is no option for you.
it's too complex and requires you to write some code too.

the above solution is ready made for you.

oh, and doc, the noooooooo! is not a reply to you.


LonkeroAdministrator
(KiX Master Guru)
2005-11-01 07:56 PM
Re: !IMPORTANT! Printmigration

actually, the delprinterconnection and addprinterconnection lines need changing too but the code itself works just fine and is a fit for your situation.

wk2x
(Fresh Scripter)
2005-11-01 08:41 PM
Re: !IMPORTANT! Printmigration

now, i'am confused..

-----------------------------------------------

$sOldPath = "\\server1"
$sNewPath = "\\server4"

Function fnRemapPrinter($sOldPath,$sNewPath)
Dim $i,$nul,$sPorts,$sDefault,$sPrinters[25]
If @INWIN=1
$sPorts="HKCU\Printers\Connections\"
$sDefault=Split(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]
Do
$sPrinters[$i]=EnumKey($sPorts,$i)
$i=$i+1
If Ubound($sPrinters)=$i Redim Preserve $sPrinters[Ubound($sPrinters)+25] EndIf
Until @ERROR
Redim Preserve $sPrinters[$i-1]
For $i = 0 to Ubound($sPrinters)
If Join(Split($sPrinters[$i],","),"\") = $sOldPath
$nul = DelPrinterConnection($sOldPath)
$nul = AddPrinterConnection($sNewPath)
If $sDefault = $sOldPath
$nul = SetDefaultPrinter($sNewPath)
EndIf
EndIf
Next
EndIf
Exit @ERROR
EndFunction

---------------------------------------

What i make false?
thank you for your help


Les
(KiX Master)
2005-11-01 09:19 PM
Re: !IMPORTANT! Printmigration

You failed to use the function. It is merely defined but nowhere is it called to action.

wk2x
(Fresh Scripter)
2005-11-01 09:39 PM
Re: !IMPORTANT! Printmigration

How i use this Script, when the old servername is server1 and the new server4
and the printer change from homeprinter1,homeprinter2... to printer1, printer2...?

Thank you for your HELP


LonkeroAdministrator
(KiX Master Guru)
2005-11-02 12:09 AM
Re: !IMPORTANT! Printmigration

just do:
fnRemapPrinter("server1","server4")

anyways, like said, you need to change these lines too:
Code:

$nul = DelPrinterConnection($sOldPath)
$nul = AddPrinterConnection($sNewPath)



to something like:
Code:

$share=Split($sPrinters[$i],",")
$share=$share[ubound($share)]
$nul = DelPrinterConnection("\\"+$sOldPath+"\"+$share)
$nul = AddPrinterConnection("\\"+$sNewPath+"\"+$share)



wk2x
(Fresh Scripter)
2005-11-02 10:25 AM
Re: !IMPORTANT! Printmigration

-------------------------------


Function fnRemapPrinter("server1","server4")
Dim $i,$nul,$sPorts,$sDefault,$sPrinters[25]
If @INWIN=1
$sPorts="HKCU\Printers\Connections\"
$sDefault=Split(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]
Do
$sPrinters[$i]=EnumKey($sPorts,$i)
$i=$i+1
If Ubound($sPrinters)=$i Redim Preserve $sPrinters[Ubound($sPrinters)+25] EndIf
Until @ERROR
Redim Preserve $sPrinters[$i-1]
For $i = 0 to Ubound($sPrinters)
$share=Split($sPrinters[$i],",")
$share=$share[ubound($share)]
$nul = DelPrinterConnection("\\server1\"+$share)
$nul = AddPrinterConnection("\\server4\"+$share)
If $sDefault = $sOldPath
$nul = SetDefaultPrinter($sNewPath)
EndIf
EndIf
Next
EndIf
Exit @ERROR
EndFunction

-------------------------------------

what i make false????....it doesn't work


Chris S.
(MM club member)
2005-11-02 02:38 PM
Re: !IMPORTANT! Printmigration

The function I posted above works at the printer level so an example of using it would look like...

Code:

fnRemapPrinter("\\oldserver\oldprinter","\\newserver\newprinter")



Here is one that remaps printers that just move to a different server, but retain the same printer share name...

Code:

fnRemapPrinters("oldserver","newserver")

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



It will remap any printer the user has installed that is pointed to the old print server and remap it to the new print server. It will also work with 9x client, but they require a reboot whereas NT-based systems do not require a reboot.


Chris S.
(MM club member)
2005-11-02 02:41 PM
Re: !IMPORTANT! Printmigration

Also, from the sample you posted it would appear that you do not understand how to use User Defined Functions (UDFs). Please read the FAQ on How to use UDFs.

LonkeroAdministrator
(KiX Master Guru)
2005-11-02 03:41 PM
Re: !IMPORTANT! Printmigration

yes, he forgot the use line I gave him.

and the modified script he has, works on server level which is lot more effiecent in his case.


NTDOCAdministrator
(KiX Master)
2005-11-03 02:39 AM
Re: !IMPORTANT! Printmigration

Still don't see why a little hand holding and using your PriMapState() UDF wouldn't work here. Worked amazingly fast and accurate for me when I used it.

I even wrote the basic structure for another Business Unit from International Support and it worked great for them too.


LonkeroAdministrator
(KiX Master Guru)
2005-11-03 02:52 AM
Re: !IMPORTANT! Printmigration

it will work.
I just don't see the reason to use it.

if you are looking for printers attached via some server, checking for each printer separately does overheat.

instead, going directly to the reg and checking all the mapped printers and moving all as needed is lot easier and no-maintenance-overheat approach.