Page 1 of 2 12>
Topic Options
#150840 - 2005-11-01 03:49 PM !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
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

Top
#150841 - 2005-11-01 05:24 PM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#150842 - 2005-11-01 05:27 PM Re: !IMPORTANT! Printmigration
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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


Top
#150843 - 2005-11-01 05:44 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
yes, i can.
HKEY_CURRENT_USER -> Connections > ,,server1,homeprinter1

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

Top
#150844 - 2005-11-01 05:46 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
Thank you for your help, but when i testing your script....
they Printers aren't make anything

Top
#150845 - 2005-11-01 06:39 PM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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+",")

_________________________
!

download KiXnet

Top
#150846 - 2005-11-01 06:54 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
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?

Top
#150847 - 2005-11-01 07:00 PM Re: !IMPORTANT! Printmigration
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#150848 - 2005-11-01 07:12 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
hmmm..interesting... have you got an example from a move script...sorry, i don't
understanding this script...

Top
#150849 - 2005-11-01 07:20 PM Re: !IMPORTANT! Printmigration
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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
 

Top
#150850 - 2005-11-01 07:54 PM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#150851 - 2005-11-01 07:56 PM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, the delprinterconnection and addprinterconnection lines need changing too but the code itself works just fine and is a fit for your situation.
_________________________
!

download KiXnet

Top
#150852 - 2005-11-01 08:41 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
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

Top
#150853 - 2005-11-01 09:19 PM Re: !IMPORTANT! Printmigration
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You failed to use the function. It is merely defined but nowhere is it called to action.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#150854 - 2005-11-01 09:39 PM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
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

Top
#150855 - 2005-11-02 12:09 AM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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)

_________________________
!

download KiXnet

Top
#150856 - 2005-11-02 10:25 AM Re: !IMPORTANT! Printmigration
wk2x Offline
Fresh Scripter

Registered: 2005-11-01
Posts: 10
-------------------------------


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

Top
#150857 - 2005-11-02 02:38 PM Re: !IMPORTANT! Printmigration
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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.

Top
#150858 - 2005-11-02 02:41 PM Re: !IMPORTANT! Printmigration
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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.
Top
#150859 - 2005-11-02 03:41 PM Re: !IMPORTANT! Printmigration
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

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
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.077 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org