tooblind
(Fresh Scripter)
2007-04-17 03:20 PM
New print server

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?

eriqjaffe
(Hey THIS is FUN)
2007-04-17 03:25 PM
Re: New print server

Take a look at the MapPrinter() UDF, it looks like it can do what you want.

tooblind
(Fresh Scripter)
2007-04-17 03:51 PM
Re: New print server

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

Glenn BarnasAdministrator
(KiX Supporter)
2007-04-17 04:36 PM
Re: New print server

Considering the example in the posted UDF is
 Code:
MapPrinter("\\a06\kenny",1,"\\oldserver\kenny")

I would imagine that you could specify the old server\printer and new server\printer just fine.

If you created tables (arrays) of old & new printer connections, you could enumerate the existing connections from the registry, AScan the array to find the OLD name in the $OLD array, and use the corresponding value in the $NEW array, passing the arguments from each array to the MapPrinter UDF.

Glenn


LonkeroAdministrator
(KiX Master Guru)
2007-04-17 10:21 PM
Re: New print server

hmm...
actually, the mapprinter lacks the logic to only map if old printer was mapped.

you would need to use primapstate() to check if printer was mapped, and then map the new one, accordingly.


tooblind
(Fresh Scripter)
2007-04-18 08:18 AM
Re: New print server

.

tooblind
(Fresh Scripter)
2007-04-18 08:25 AM
Re: New print server

[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:

 Code:
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


Glenn BarnasAdministrator
(KiX Supporter)
2007-04-18 01:54 PM
Re: New print server

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:
 Code:
[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.
 Code:
$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


tooblind
(Fresh Scripter)
2007-04-24 03:56 PM
Re: New print server

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!

tooblind
(Fresh Scripter)
2007-04-30 11:36 AM
Re: New print server

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!

eriqjaffe
(Hey THIS is FUN)
2007-04-30 03:39 PM
Re: New print server

Something along these lines should do the job, just add code as needed for the printers you're migrating:

 Code:
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.