#171357 - 2006-12-12 11:17 AM
,Adding/removing network printers
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
Hi
|
|
Top
|
|
|
|
#171358 - 2006-12-12 11:20 AM
Re: ,Adding/removing network printers
[Re: Dugster]
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
Sorry - very new to this!
I'm trying to write a script to add and remove networked printers. I need to say something like.....
If user is connected to \\oldserver\oldprinter then add \\newserver\newprinter and delete \\oldserver\oldprinter
with possibility of setting it to default if old printer was default.
If anyone can give me some pointers as to how to script this I would be eternally grateful. Thanks
|
|
Top
|
|
|
|
#171360 - 2006-12-12 12:55 PM
Re: ,Adding/removing network printers
[Re: Dugster]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I think the PriMapState() UDF can help you. I presume your old printer server should still be running PriMapState("\\OldServer\Printer1") will return 1 if printer connected 2 if printer is default nothing if not connected I presume you can create a script enumerating all of your printers on the old server and if 1 or 2 is returned, remove it, install the one from the new server and if return was 2, make it default.
|
|
Top
|
|
|
|
#171517 - 2006-12-14 05:27 PM
Re: ,Adding/removing network printers
[Re: Witto]
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
Thanks for that - the link looks like a good one. Unfortunately I'm totally clueless here - how would you enumerate the printers? Also I assume in the script you sent $_Pri is replaced by the printer share? As I say - completely clueless! Really appreciate any advice..
|
|
Top
|
|
|
|
#171519 - 2006-12-14 06:34 PM
Re: ,Adding/removing network printers
[Re: Dugster]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I presume you know all your printers on your printer server? Just create your own array. I presume the same printers have been created on the new server... I also presume that printer names and printer shares have the same name? You should not replace the $_Pri. You keep the UDF as it is and add it p.e. at the end of your script. Here is a script that I did not test!!!
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption("Explicit", "ON")
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("WrapAtEOL", "ON")
Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL
$OldServer = "OldServer"
$NewServer = "NewServer"
$ArrPtrs = Split("Printer1,Printer2,Printer3",",")
For Each $Ptr In $ArrPtrs
$PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr)
If 0 < $PtrMapState
$NUL = DelPrinterConnection($Ptr)
If NOT @ERROR
$NUL = AddPrinterConnection("\\" + $NewServer + "\" $Ptr)
If 2 = $PtrMapState
$NUL = SetDefaultPrinter("\\" + $NewServer + "\" $Ptr)
EndIf
Else
? "Error deleting Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
EndIf
Next
|
|
Top
|
|
|
|
#171529 - 2006-12-14 07:29 PM
Re: ,Adding/removing network printers
[Re: Dugster]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
|
|
Top
|
|
|
|
#171670 - 2006-12-18 03:01 PM
Re: ,Adding/removing network printers
[Re: NTDOC]
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
I really appreciate all the advice and help you've given me here. I have managed to make the script work with one printer but have one *last* question for you about making the script work for multiple printers.
In the script Witto sent above there is the following entry:
$ArrPtrs = Split("Printer1,Printer2,Printer3",",") For Each $Ptr In $ArrPtrs
I can't get this to work. If I just say $Ptr = "printername" and remove the $ArrPtrs bit, the script runs fine (with a couple of tweaks). Just wondering if I can make the multiple printers re-map in one script or if I should do a script for each printer?
Thanks a lot
|
|
Top
|
|
|
|
#171675 - 2006-12-18 05:05 PM
Re: ,Adding/removing network printers
[Re: Glenn Barnas]
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
Its ok - I got it working. Thanks a lot for your time and help on this.
|
|
Top
|
|
|
|
#171703 - 2006-12-18 11:43 PM
Re: ,Adding/removing network printers
[Re: Dugster]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I hope you also implemented something like Jooel suggested:
don't delete the old printer before the new one maps fine
I think this would be better, but again, I did not test it
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption("Explicit", "ON")
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("WrapAtEOL", "ON")
Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL
$OldServer = "OldServer"
$NewServer = "NewServer"
$ArrPtrs = Split("Printer1,Printer2,Printer3",",")
For Each $Ptr In $ArrPtrs
$PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr)
If 0 < $PtrMapState
$NUL = AddPrinterConnection("\\" + $NewServer + "\" $Ptr)
If NOT @ERROR AND 2 = $PtrMapState
$NUL = SetDefaultPrinter("\\" + $NewServer + "\" $Ptr)
If @ERROR
? "Error setting default Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
Else
? "Error adding Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
If NOT @ERROR
$NUL = DelPrinterConnection($Ptr)
If @ERROR
? "Error deleting Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
EndIf
EndIf
Next
If AddPrinterConnection generates an error, or if AddprinterConnection succeeds but SetDefaultPrinter generates an error, DelPrinterConnection should not be executed.
|
|
Top
|
|
|
|
#171736 - 2006-12-19 05:48 PM
Re: ,Adding/removing network printers
[Re: Witto]
|
Dugster
Fresh Scripter
Registered: 2006-12-12
Posts: 11
|
Thanks for that. I made a couple of changes to get this to work but basically you've helped a great deal. For info the working script is as follows:
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption("Explicit", "ON")
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("WrapAtEOL", "ON")
Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL
$OldServer = "OldServer"
$NewServer = "NewServer"
$ArrPtrs = Split("Printer1,Printer2,Printer3",",")
For Each $Ptr In $ArrPtrs
$PtrMapState = PriMapState("\\" + $OldServer + "\" + $Ptr)
If 0 < $PtrMapState
$NUL = AddPrinterConnection("\\" + $NewServer + "\" + $Ptr)
If NOT @ERROR AND 2 = $PtrMapState
$NUL = SetDefaultPrinter("\\" + $NewServer + "\" + $Ptr)
If @ERROR
? "Error setting default Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
Else
IF @ERROR
? "Error adding Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
EndIf
If NOT @ERROR
$NUL = DelPrinterConnection("\\" + $OldServer + "\" + $Ptr)
If @ERROR
? "Error deleting Printer Connection " + $Ptr
? "Error " + @ERROR + ": " + @SERROR
EndIf
EndIf
EndIf
Next
If AddPrinterConnection generates an error, or if AddprinterConnection succeeds but SetDefaultPrinter generates an error, DelPrinterConnection should not be executed.[/quote]
|
|
Top
|
|
|
|
#173802 - 2007-02-09 04:15 PM
Re: ,Adding/removing network printers
[Re: Dugster]
|
LANSonic
Lurker
Registered: 2007-02-08
Posts: 3
|
Dugster, I would love to try this script, but I have 100 network printers to move to the new print server. How can I wrap the text in $AppPtrs declaration so I can include all 100 names? Would it be similar to this? Code ____________________________________________________________________ $ArrPtrs = Split("Printer1,Printer2,Printer3, _ Printer4,Printer5,Printer6,Printer7,Printer8, _ Printer9",",") ____________________________________________________________________ End Code
Thanks in advance for your help.
|
|
Top
|
|
|
|
#173803 - 2007-02-09 04:25 PM
Re: ,Adding/removing network printers
[Re: LANSonic]
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Hi LANSonic, and welcome to the board. You should review The Post/Reply Formatting Box and How to use it.
The use of the underscore is for vbscript, with KiXtart it would look like this:
$ArrPtrs = Split("Printer1,Printer2,Printer3,
Printer4,Printer5,Printer6,Printer7,Printer8,
Printer9",",")
|
|
Top
|
|
|
|
#173804 - 2007-02-09 04:30 PM
Re: ,Adding/removing network printers
[Re: Benny69]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
LANSonic, Maybe you can ask your questions about your topic in your own thread? http://www.kixtart.org/forums/ubbthreads...true#Post173784 I am very sure everybody is very willing to answer you, as you can see.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 560 anonymous users online.
|
|
|