#175436 - 2007-04-17 03:20 PM
New print server
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
I've copied all the printers from a NT server to a 2003 printserver and changed all the names. How do I automatically delete the old printer and map the new printer on the new server on all the computers via logonscript?
|
Top
|
|
|
|
#175437 - 2007-04-17 03:25 PM
Re: New print server
[Re: tooblind]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Take a look at the MapPrinter() UDF, it looks like it can do what you want.
|
Top
|
|
|
|
#175439 - 2007-04-17 03:51 PM
Re: New print server
[Re: eriqjaffe]
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
It seems like that only delete the old printer og connects to a printer with the same name on the new server. My problem is that every printer I moved, has got a new name, and I need a script that somehow connects the old and the new printer regardless on what the printer's name is.
Thanks in advance
|
Top
|
|
|
|
#175463 - 2007-04-18 08:18 AM
Re: New print server
[Re: Lonkero]
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
.
Edited by tooblind (2007-04-18 08:19 AM)
|
Top
|
|
|
|
#175464 - 2007-04-18 08:25 AM
Re: New print server
[Re: Lonkero]
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
[font:Microsoft Sans Serif]I do not have any experience in scripting, and I appreciate all the help I can get.
I have to map around 50 network printers, and I don't understand how I am gonna do that with this script. Should I map the all the new printers, and delete the old one by listing all 50 in this script, so it would be f.ex:
function MapPrinter("\\2003 server\printer01",1,"\\NTserver\hp4000")
function MapPrinter("\\2003 server\printer02",1,"\\NTserver\hp3500")
function MapPrinter("\\2003 server\printer03",1,"\\NTserver\hplaser")
function MapPrinter("\\2003 server\printer04",1,"\\NTserver\konminpcl")
function MapPrinter("\\2003 server\printer05",1,"\\NTserver\konminps")
function MapPrinter("\\2003 server\printer06",1,"\\NTserver\hp200")
DIM $index,$IsInstalled,$lptprinter,$inst_printers,$PrinterPorts,$port_type
$index=0 $IsInstalled=0 $lptprinter=0
$PrinterPorts="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts"
if $oldspool
$=DelPrinterConnection($oldspool)
endif
:loopprinters
$inst_printers=enumvalue($PrinterPorts,$index)
if @error=0
$port_type=readvalue("$PrinterPorts","$inst_printers")
if $printer=$inst_printers $IsInstalled=1 endif
if instr("$port_type","LPT") $lptprinter=1 endif
$index=$index+1
goto loopprinters
endif
if $IsInstalled=0
$=AddPrinterConnection("$printer")
endif
if $IsInstalled=0 and $lptprinter=0 and $default
$=SetDefaultPrinter("$printer")
endif
endfunction
Again I'm sorry that I don't understand this better, so I really appreciate all the help I can get
|
Top
|
|
|
|
#175467 - 2007-04-18 01:54 PM
Re: New print server
[Re: tooblind]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
First off, you don't use "FUNCTION" more than once. The FUNCTION function is used to define a new function - once it's defined, you reference it like any other built-in command. You would insert the MapPrinter code to either the very beginning or very end (my preference) of your script, without any changes. Kix will locate any Function definitions first, so they are available to your script logic.
I suggested that you utilize the logic of the mapprinter to decide what to do. Here's a few more thoughts..
Create a PRINTERS.INI file that looks like this:
[PRINTERS]
NewPrint1=OldPrint1
NewPrint2=OldPrint2
NewPrint3=0
This provides a list of every new printer name, and the corresponding printer it replaced. If it is an additional printer and did not replace one, just set the old printer name to zero.
You can now easily get a list of the new printers by using the ReadProfileString function. Enumerate the list and get the names of the old printers for each new one. If the old name is zero ("0"), then there is no old printer to worry about.
$NewPrint = ReadProfileString(@SCRIPTDIR + 'printers.ini', 'PRINTERS')
For Each $Printer in $NewPrint
$OldPrint = ReadProfileString(@SCRIPTDIR + 'printers.ini', 'PRINTERS', $Printer)
'Processing ' $Printer ; identify current printer
If $OldPrint = 0
' - adding new!' ? ; no old printer
; Just map the new printer
Else
' - removing ' $OldPrint ? ; removing old printer
; see if $OldPrint is defined, if it is, use MapPrinter() to
; remove the old and define the new, otherwise, simply add
; the new printer connection. You might want to modify MapPrinter
; to check for the printer, and map only if the old printer is defined
; or - put the decision logic here - addprinterconnection() if
; $OldPrint is 0 else MapPrinter(new,1,old)
;
; insert your preferred logic here...
;
EndIf
' ' @SERROR ? ? ; indent result message and skip extra line
Next
Start small - just list a few printers in your INI file for testing. During testing, don't call the functions, print messages telling you what the code would do.. when it seems like the logic is correct, fill in the remaining printers in the INI file and uncomment the lines that do the actual work.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#175623 - 2007-04-24 03:56 PM
Re: New print server
[Re: Glenn Barnas]
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
So this is a whole new script? I'm not gonna use the first one I got? I'm sorry, but I'm as dumb as a stone when it comes to scripting. I really need help. Please help me anyone!
|
Top
|
|
|
|
#175809 - 2007-04-30 11:36 AM
Re: New print server
[Re: tooblind]
|
tooblind
Fresh Scripter
Registered: 2007-04-17
Posts: 6
|
I really need help with this one. What I need is to have a script that says something like: If oldprint 01 excists, install newprint01 and delete oldprint01. All the printers has a new name and a new printserver. Please help me!
|
Top
|
|
|
|
#175815 - 2007-04-30 03:39 PM
Re: New print server
[Re: tooblind]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Something along these lines should do the job, just add code as needed for the printers you're migrating:
select
case PriMapState("\\OldPrintServer\Printer1") = 1
MapPrinter("\\NewPrintServer\PrinterX",,"\\OldPrintServer\Printer1")
case PriMapState("\\OldPrintServer\Printer1") = 2
MapPrinter("\\NewPrintServer\PrinterX",1,"\\OldPrintServer\Printer1")
endselect That relies on the MapPrinter() and the PriMapState() UDF's.
Edited by eriqjaffe (2007-04-30 03:40 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|