#134000 - 2005-02-17 07:18 PM
Problem with simple printer mapping script
|
SGoddard
Lurker
Registered: 2005-02-17
Posts: 3
|
Trying to use a very simple printer mapping script that looks to the computer name. The scrip keeps mapping all the printers regardless of the computer name! Any ideas??
;*******************************************
;NT/2K/XP workstation variables (set using SET command)
SET COMPUTER="@WKSTA"
;******************************************************
IF @WKSTA ("S101"|"S102"|"S103"|"S104"|"S105"|"S106"|"S107"|"S108"|"S109"|"S110"|"S111 "|"S112"|"S113"|"S114"|"S215"|"S116"|"S117"|"S118"|"S119"|"S120"|"S121"|"S12 2"|"S123"|"S124"|"S125"|"S126"|"S127"|"S128"|"S129"|"S130") IF AddPrinterConnection ("\\admin1\ICT1_Las") = 1 MESSAGEBOX ("ICT1 Laser Printer connection failed","Printer Connection Error!",0) ENDIF ENDIF
;********************************************************
IF @WKSTA ("S201"|"S202"|"S203"|"S204"|"S205"|"S206"|"S207"|"S208"|"S209"|"S210"|"S211 "|"S212"|"S213"|"S214"|"S215"|"S216"|"S217"|"S218"|"S219"|"S220"|"S221"|"S22 2"|"S223"|"S224"|"S225"|"S226"|"S227"|"S228"|"S229"|"S230") IF AddPrinterConnection ("\\admin1\ICT2_Las") = 1 MESSAGEBOX ("ICT2 Laser Printer connection failed","Printer Connection Error!",0) ENDIF ENDIF
;********************************************************
IF @WKSTA ("S301"|"S302"|"S303"|"S304"|"S305"|"S306"|"S307"|"S308"|"S309"|"S310"|"S311 "|"S312"|"S313"|"S314"|"S315"|"S316"|"S317"|"S318"|"S319"|"S320"|"S321"|"S32 2"|"S323"|"S324"|"S325"|"S326"|"S327"|"S328"|"S329"|"S330") IF AddPrinterConnection ("\\admin1\ICT3_Las") = 1 MESSAGEBOX ("ICT3 Laser Printer connection failed","Printer Connection Error!",0) ENDIF ENDIF
;********************************************************
IF @WKSTA ("S401"|"S402"|"S403"|"S404"|"S405"|"S406"|"S407"|"S408"|"S409"|"S410") IF AddPrinterConnection ("\\admin1\ICT4_Las") = 1 MESSAGEBOX ("ICT4 Laser Printer connection failed","Printer Connection Error!",0) ENDIF ENDIF
;********************************************************
IF @WKSTA ("TECHNICIAN01") IF AddPrinterConnection ("\\technician02\Technician") = 1 MESSAGEBOX ("Technician Laser Printer connection failed","Printer Connection Error!",0) ENDIF ENDIF
;********************************************************
IF @WKSTA ("ART01"|"ART02") IF AddPrinterConnection ("\\admin1\Art_Col") = 1 MESSAGEBOX ("Art Laser Colour connection failed","Printer Connection Error!",0) ENDIF ENDIF
;****************************************************
|
|
Top
|
|
|
|
#134001 - 2005-02-17 09:14 PM
Re: Problem with simple printer mapping script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Code:
IF @WKSTA ("S101"|"S102"|"S103"|"S104"|"S105"|"S106"|"S107"|"S108"|"S109"|"S110"|"S111
"|"S112"|"S113"|"S114"|"S215"|"S116"|"S117"|"S118"|"S119"|"S120"|"S121"|"S12
2"|"S123"|"S124"|"S125"|"S126"|"S127"|"S128"|"S129"|"S130")
Your IF construct is not valid.
Code:
select
case instr("~S101~S102~S103~S104~S105~S106~S107~S108~S109~S110~S111~S112~S113~S114~" +
"S215~S116~S117~S118~S119~S120~S121~S122~S123~S124~S125~S126~S127~S128~S129~S130~", "~"+@wksta+"~")
;do printer stuff
case something else
case 1 ; catch anything that was not caught above
Endselect
or
if @wksta = "S101" or @wksta = "S102" or ...
Edited by Howard Bullock (2005-02-17 09:20 PM)
|
|
Top
|
|
|
|
#134003 - 2005-02-18 12:03 AM
Re: Problem with simple printer mapping script
|
Anonymous
Anonymous
Unregistered
|
Thanks - that is a great help. So would the following be valid?
Code:
;***************************************************************************
;******** Map Printers by Computer Name ************************************
;***************************************************************************
select
case instr("~S101~S102~S103~S104~S105~S106~S107~S108~S109~S110~S111~S112~S113~S114~" +
"S115~S116~S117~S118~S119~S120~S121~S122~S123~S124~S125~S126~S127~S128~S129~S130~", "~"+@wksta+"~")
IF AddPrinterConnection ("\\admin1\ICT1_Las") = 1
MESSAGEBOX ("ICT1 Laser Printer connection failed","Printer Connection Error!",0)
ENDIF
case instr("~S201~S202~S203~S204~S205~S206~S207~S208~S209~S210~S211~S212~S213~S214~" +
"S215~S216~S217~S218~S219~S220~S221~S222~S223~S224~S225~S226~S227~S228~S229~S230~", "~"+@wksta+"~")
IF AddPrinterConnection ("\\admin1\ICT2_Las") = 1
MESSAGEBOX ("ICT2 Laser Printer connection failed","Printer Connection Error!",0)
ENDIF
case instr("~S301~S302~S303~S304~S305~S306~S307~S308~S309~S310~S311~S312~S313~S314~" +
"S315~S316~S317~S318~S319~S320~S321~S322~S323~S324~S325~S326~S327~S328~S329~S330~", "~"+@wksta+"~")
IF AddPrinterConnection ("\\admin1\ICT3_Las") = 1
MESSAGEBOX ("ICT3 Laser Printer connection failed","Printer Connection Error!",0)
ENDIF
case instr("~S401~S402~S403~S404~S405~S406~S407~S408~S409~S410~", "~"+@wksta+"~")
IF AddPrinterConnection ("\\admin1\ICT4_Las") = 1
MESSAGEBOX ("ICT4 Laser Printer connection failed","Printer Connection Error!",0)
ENDIF
case 1 ; catch anything that was not caught above
Endselect
Added code tags - Bullock
Edited by Howard Bullock (2005-02-18 12:10 AM)
|
|
Top
|
|
|
|
#134004 - 2005-02-18 12:13 AM
Re: Problem with simple printer mapping script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Not correct yet. You may not get a "1" returned. Please review the return codes for:
Code:
AddPrinterConnection( )
Action: Adds a connection to the specified printer for the current user.
Syntax: ADDPRINTERCONNECTION ("printer name")
Parameters: Printer name
The (share)name of the printer to which to connect.
Remarks: This function is available only on Windows NT family, and can be used only to
connect to printers on a server running the Windows NT/2000/XP operating system.
When Windows NT connects to the printer, it may copy printer driver files to the local computer. If the user does not have permission to copy files to the appropriate location, ADDPRINTERCONNECTION fails, and @ERROR returns ERROR_ACCESS_DENIED.
Returns: 0 Printer connection established
Error code Function failed
See Also: DelPrinterConnection( ), SetDefaultPrinter( )
Example: If ADDPRINTERCONNECTION ("\\vleerbeer\hp laserjet 4") = 0
? "Added printer connection...."
Endif
Edited by Howard Bullock (2005-02-18 12:15 AM)
|
|
Top
|
|
|
|
#134005 - 2005-02-18 12:25 AM
Re: Problem with simple printer mapping script
|
SGoddard
Lurker
Registered: 2005-02-17
Posts: 3
|
Thanks again... ok 3rd time lucky. How does this look (I have kind of assumed I can use ELSE statements!)
;***************************************************************************
;******** Map Printers by Computer Name ************************************
;***************************************************************************
select case instr("~S101~S102~S103~S104~S105~S106~S107~S108~S109~S110~S111~S112~S113~S114~" + "S115~S116~S117~S118~S119~S120~S121~S122~S123~S124~S125~S126~S127~S128~S129~S130~", "~"+@wksta+"~") IF AddPrinterConnection ("\\admin1\ICT1_Las") = 0 MESSAGEBOX ("ICT1 Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("ICT1 Laser Printer connection failed","Printer Connection Error!",0) ENDIF case instr("~S201~S202~S203~S204~S205~S206~S207~S208~S209~S210~S211~S212~S213~S214~" + "S215~S216~S217~S218~S219~S220~S221~S222~S223~S224~S225~S226~S227~S228~S229~S230~", "~"+@wksta+"~") IF AddPrinterConnection ("\\admin1\ICT2_Las") = 0 MESSAGEBOX ("ICT2 Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("ICT2 Laser Printer connection failed","Printer Connection Error!",0) ENDIF case instr("~S301~S302~S303~S304~S305~S306~S307~S308~S309~S310~S311~S312~S313~S314~" + "S315~S316~S317~S318~S319~S320~S321~S322~S323~S324~S325~S326~S327~S328~S329~S330~", "~"+@wksta+"~") IF AddPrinterConnection ("\\admin1\ICT3_Las") = 0 MESSAGEBOX ("ICT3 Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("ICT3 Laser Printer connection failed","Printer Connection Error!",0) ENDIF case instr("~S401~S402~S403~S404~S405~S406~S407~S408~S409~S410~", "~"+@wksta+"~") IF AddPrinterConnection ("\\admin1\ICT4_Las") = 0 MESSAGEBOX ("ICT4 Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("ICT4 Laser Printer connection failed","Printer Connection Error!",0) ENDIF case instr("~TECHNICIAN01~", "~"+@wksta+"~") IF AddPrinterConnection ("\\technician02\Technician") = 0 MESSAGEBOX ("Technician Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("Technician Laser Printer connection failed","Printer Connection Error!",0) ENDIF case instr("~ART01~ART02~", "~"+@wksta+"~") IF AddPrinterConnection ("\\admin1\Art_Col") = 0 MESSAGEBOX ("Art Laser Printer Connected!","Printer Connected!",0) ELSE MESSAGEBOX ("Art Laser Colour connection failed","Printer Connection Error!",0) ENDIF case 1 ; catch anything that was not caught above Endselect
;***************************************************************************
|
|
Top
|
|
|
|
#134006 - 2005-02-18 12:28 AM
Re: Problem with simple printer mapping script
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Here, please make sure you're using KiXtart 4.22 or 4.23 and give this a try.
;***************************************************************************
;******** Map Printers by Computer Name ************************************
;***************************************************************************
Break On
Dim $PrintGroup01,$PrintGroup02,$PrintGroup03,$PrintGroup04,$Msg
$PrintGroup01=Split('S101|S102|S103|S104|S105|S106|S107|S108|S109|S110|S111|S112|S113|S114|' +
'S115|S116|S117|S118|S119|S120|S121|S122|S123|S124|S125|S126|S127|S128|S129|S130','|')
$PrintGroup02=Split('S201|S202|S203|S204|S205|S206|S207|S208|S209|S210|S211|S212|S213|S214|' +
'S215|S216|S217|S218|S219|S220|S221|S222|S223|S224|S225|S226|S227|S228|S229|S230','|')
$PrintGroup03=Split('S301|S302|S303|S304|S305|S306|S307|S308|S309|S310|S311|S312|S313|S314|' +
'S315|S316|S317|S318|S319|S320|S321|S322|S323|S324|S325|S326|S327|S328|S329|S330','|')
$PrintGroup04=Split('S401|S402|S403|S404|S405|S406|S407|S408|S409|S410','|')
Select
Case AScan($PrintGroup01,@WKSTA)>=0
If AddPrinterConnection('\\admin1\ICT1_Las')<>0
$Msg=MessageBox('ICT1 Laser Printer connection failed','Printer Connection Error!',16)
EndIf
Case AScan($PrintGroup02,@WKSTA)>=0
If AddPrinterConnection('\\admin1\ICT2_Las')<>0
$Msg=MessageBox('ICT2 Laser Printer connection failed','Printer Connection Error!',16)
EndIf
Case AScan($PrintGroup03,@WKSTA)>=0
If AddPrinterConnection('\\admin1\ICT3_Las')<>0
$Msg=MessageBox('ICT3 Laser Printer connection failed','Printer Connection Error!',16)
EndIf
Case AScan($PrintGroup04,@WKSTA)>=0
If AddPrinterConnection('\\admin1\ICT4_Las')<>0
$Msg=MessageBox('ICT4 Laser Printer connection failed','Printer Connection Error!',16)
EndIf
Case 1
$Msg=MessageBox('Unable to determine which printer to install.' + @CRLF +
'Your system ' + @WKSTA + ' was not found in the list.','Printer Connection Error!',16)
EndSelect
|
Edited by NTDOC (2005-02-18 12:42 AM)
|
|
Top
|
|
|
|
#134007 - 2005-02-18 12:32 AM
Re: Problem with simple printer mapping script
|
SGoddard
Lurker
Registered: 2005-02-17
Posts: 3
|
Cheers mate - very nice script. I won't be able to try it till Monday - I'll try and let you know if it works. I think I'm using the latest version of kix so should be fine.
Steve
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 640 anonymous users online.
|
|
|