#19277 - 2002-03-29 09:06 PM
there has to be a better way
|
kdog
Fresh Scripter
Registered: 2002-02-19
Posts: 11
|
We have over 100 printers that users need to default to in our citrix farm. Anyone have any ideas on how this code could be cleaned up ? THANKS you guys are rockstars with kix!
IF INGROUP ("WELGN") SetDefaultPrinter ("welgn01") ENDIF
IF INGROUP ("Lsbprt") SetDefaultPrinter ("lsb01") ENDIF
IF INGROUP ("Whitefishbay") SetDefaultPrinter ("wbay") ENDIF
IF INGROUP ("Newberlin") SetDefaultPrinter ("nbe01") ENDIF
IF INGROUP ("Foxpoint") SetDefaultPrinter ("foxpoint") ENDIF
IF INGROUP ("BARTLETT") SetDefaultPrinter ("bart") ENDIF
IF INGROUP ("BROADWAY") SetDefaultPrinter ("brdwy") ENDIF
IF INGROUP ("BRKPRT02") SetDefaultPrinter ("brktlr") ENDIF
IF INGROUP ("BRKPRT01") SetDefaultPrinter ("brklob") ENDIF
IF INGROUP ("BURPRT") SetDefaultPrinter ("bur01") ENDIF
IF INGROUP ("CRYSTAL LAKE") SetDefaultPrinter ("CRL01") ENDIF
IF INGROUP ("ELGIN") SetDefaultPrinter ("elgin01") ENDIF
IF INGROUP ("Elgin Loans1") SetDefaultPrinter ("elgloans1") ENDIF
IF INGROUP ("ELKPRT01") SetDefaultPrinter ("elklob") ENDIF
IF INGROUP ("ELKPRT02") SetDefaultPrinter ("elktlr") ENDIF
IF INGROUP ("GLDPRT01") SetDefaultPrinter ("gldlob") ENDIF
IF INGROUP ("GLDPRT02") SetDefaultPrinter ("gldtlr") ENDIF
IF INGROUP ("DWRPRT01") SetDefaultPrinter ("dwrlob") ENDIF
IF INGROUP ("DWRPRT02") SetDefaultPrinter ("dwrtlr") ENDIF
IF INGROUP ("GLEN OAK") SetDefaultPrinter ("glenoak") ENDIF
IF INGROUP ("GLENVIEW") SetDefaultPrinter ("glnview") ENDIF
IF INGROUP ("GREENFIELD PRINTER") SetDefaultPrinter ("GRF01") ENDIF
IF INGROUP ("GREENFIELD PRT2") SetDefaultPrinter ("GRF02") ENDIF
IF INGROUP ("GURNEE") SetDefaultPrinter ("gurnee") ENDIF
IF INGROUP ("HILLPRT") SetDefaultPrinter ("hill01") ENDIF
IF INGROUP ("HLCLOBNRT") SetDefaultPrinter ("hlclbyn") ENDIF
IF INGROUP ("HLCLOBSTH") SetDefaultPrinter ("hlclbys") ENDIF
IF INGROUP ("HLC Bankers") SetDefaultPrinter ("hlclbnth") ENDIF
IF INGROUP ("HLC LOANS") SetDefaultPrinter ("hlcloan") ENDIF
IF INGROUP ("HLC 3RD") SetDefaultPrinter ("hc3rdflr") ENDIF
IF INGROUP ("HLC tellers") SetDefaultPrinter ("hlctlr") ENDIF
IF INGROUP ("HLCPRF01") SetDefaultPrinter ("HLCPRF01") ENDIF
IF INGROUP ("AICBCK") SetDefaultPrinter ("AICBCK") ENDIF
IF INGROUP ("AICFRNT") SetDefaultPrinter ("AICFRT") ENDIF
IF INGROUP ("LIBERTYVILLE") SetDefaultPrinter ("lbrtyvl") ENDIF
IF INGROUP ("MSKBNKR") SetDefaultPrinter ("msk01") ENDIF
IF INGROUP ("RICHMOND BNK") SetDefaultPrinter ("rch01") ENDIF
IF INGROUP ("RCHINV") SetDefaultPrinter ("RCHINV") ENDIF
IF INGROUP ("ROSELLE") SetDefaultPrinter ("rose") ENDIF
IF INGROUP ("SOUTH ELGIN") SetDefaultPrinter ("selgn") ENDIF
IF INGROUP ("WELGN") SetDefaultPrinter ("welgn01") ENDIF
IF INGROUP ("Waterstreet") SetDefaultPrinter ("watrst01") ENDIF
IF INGROUP ("Waterstreet2") SetDefaultPrinter ("watrst02") ENDIF
IF INGROUP ("Waterstreet3") SetDefaultPrinter ("watrst03") ENDIF
|
|
Top
|
|
|
|
#19279 - 2002-03-29 10:11 PM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
How about something like this:
code:
; Get the global groups to which the user is a member ; $Index = 0 $PrinterSet = 0 $NonPrinterGrps = "Domain Users,Domain Admins,Some Other Grps" $Domain = "@Ldomain\" DO $Group = ENUMGROUP($Index) if instr($Group, $Domain) $Group = substr($Group,len($Domain)+1) if instr($NonPrinterGrps, $Group)=0 $Printer = ReadProfileString("printer.ini", "Printers", "$Group") if $Printer <> "" SetDefaultPrinter ($Printer) $PrinterSet = 1 endif endif endif $Index=$Index+1 UNTIL $PrinterSet=1 or Len($Group) = 0
Then create your printer mapping file in INI file format. code:
;Printer configuration mapping file [Printers] WELGN=welgn01 Lsbprt=lsb01 Whitefishbay=wbay Newberlin=nbe01 Foxpoint=foxpoint BARTLETT=bart
[ 29 March 2002, 22:29: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19280 - 2002-03-29 10:38 PM
Re: there has to be a better way
|
kdog
Fresh Scripter
Registered: 2002-02-19
Posts: 11
|
wow ! Rockstar ! I do have one question .. The variable $NonPrinterGrps should I enter all of the groups that exist in the domain are not related to printing in this area ?
|
|
Top
|
|
|
|
#19281 - 2002-03-29 10:46 PM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
That really depends on how many that is. The idea of "$NonPrinterGrps" an "if instr($NonPrinterGrps, $Group)=0" is to quickly eliminate a group that will not be found in the Printers.ini file. If you do not include any groups in $NonPrinterGrps then the loop attempts to find the all groups in printers.ini. It won't find it and loops. The trick here is to find a balance I think. The true answer depends on which is less overhead the instr function or the ReadProfileString for all groups. You may have to test it each way to determine which is the fastest. [ 29 March 2002, 23:04: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19282 - 2002-03-29 11:28 PM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Actually you also have to consider how many groups a user may belong to. If each user is a member of 5 or 6 groups, and you use $NonPrinterGrps to eliminate the groups common to all such as ""Domain Users,Domain Admins" plus any common or popular groups in your environment, the overhead of checking a few groups per user should be small. [ 29 March 2002, 23:28: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19283 - 2002-04-02 10:01 PM
Re: there has to be a better way
|
kdog
Fresh Scripter
Registered: 2002-02-19
Posts: 11
|
Not sure if this is working correctly . I created a test user called rsteel and added him to the global groups domain user and welgn This should then set his default windows printer to welgn01 Here is my script: IF EXIST ("C:\SERVER.TXT") GOTO "CTX"
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN SUBNET DETECTION%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$OCT1 = LTRIM(SUBSTR(@IPADDRESS0, 1, 3)) $OCT2 = LTRIM(SUBSTR(@IPADDRESS0, 5, 3)) $OCT3 = LTRIM(SUBSTR(@IPADDRESS0, 9, 3)) $OCT4 = LTRIM(SUBSTR(@IPADDRESS0, 13, 3)) $GT = (INGROUP ("GLBTLR")) $GR = (INGROUP ("GLBRPT"))
$sKey="IP." + $OCT2 + "." + $OCT3 $sServer=ReadProfileString ("@LSERVER\netlogon\servers.ini","SERVER",$SKey)
IF $GT USE G: "\\" + $sSERVER + "bdc\PCTSHR" EndIF IF $GR USE F: "\\" + $sSERVER + "bdc\RPTSHR" EndIF
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%%% BEGIN NON CITRIX DRIVE MAPPINGS%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IF INGROUP ("DOMAIN USERS") USE K: \\data01\CMN USE U: "\\data01\@USERID" ENDIF
IF INGROUP ("hr")
USE P: \\hrorcl1\ADPHR USE H: \\hrorcl1\DOCS ENDIF IF INGROUP ("INSURANCE") USE F: \\ins01\INS ENDIF
IF INGROUP ("ap") USE I: \\nthales\ips ENDIF
IF INGROUP ("GLBRPT") USE R: \\HLC01SAN\VOL1 ENDIF
:CTX ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%% BEGIN CITRIX DRIVE MAPPINGS%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%&&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IF INGROUP ("DOMAIN USERS") USE K: \\DATA01\CMN USE U: "\\data01\@USERID" ENDIF
IF INGROUP ("IPS") USE T: \\NTHALES\IPS ENDIF
IF INGROUP ("hr") USE P: \\HRORCL1\ADPHR USE H: \\HRORCL1\DOCS
ENDIF
IF INGROUP ("HLC tellers") USE G: \\pctsql01\01 ENDIF
IF INGROUP ("BANKER INSIGHT") USE F: /DEL USE F: \\bi3\bi ENDIF
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%% BEGIN DEFAULT PRINTER SET %%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%&&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$Index = 0 $PrinterSet = 0 $NonPrinterGrps = "Domain Users,Domain Admins,Network Admins" $Domain = "SFSC\" Do $Group = ENUMGROUP($Index) IF instr($Group, $Domain) $Group = substr($Group,len($Domain)+1) If instr($NonPrinterGrps, $Group)=0 $Printer = ReadProfileString("rinter.ini", "Printers", "$Group") IF $Printer <> "" SetDefaultPrinter ($Printer) $PrinterSet = 1 endif endif endif $Index=$index+1 UNTIL $PrinterSet=1 or Len ($Group) = 0 ? $Printer ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%% END DEFAULT PRINTER SET %%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%&&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;---------------------------------------------------- ; ------ Begin Mobile User Settings ----------------- ;----------------------------------------------------
cls SETCONSOLE ("SHOW") IF INGROUP ("MOBILE USERS")
? "PLEASE SELECT THE OFFICE" ? "YOU ARE WORKING AT TODAY" ? " PRESS 8 FOR RICHMOND" ? " PRESS 7 FOR WATERFORD" ? " PRESS 6 FOR WATERSTREET 1" ? " PRESS 5 FOR WATERSTREET 2" ? " PRESS 4 FOR LISBON" ? " PRESS 3 FOR WHITEFISH BAY" ? " PRESS 2 FOR NEW BERLIN" ? " PRESS 1 FOR FOXPOINT"
; DO NOT ADD ANY INFORMATION BELOW THIS LINE
FLUSHKB GET $A
IF "$A" = "8" GOTO RCH ELSE "ENDIF" IF "$A" = "7" GOTO WAT2 ELSE "ENDIF" IF "$A" = "6" GOTO WTR1 ELSE "ENDIF" IF "$A" = "5" GOTO WTR2 ElSE "ENDIF" IF "$A" = "4" GOTO LBN ELSE "ENDIF" IF "$A" = "3" GOTO WBY ELSE "ENDIF" IF "$A" = "2" GOTO NBR ELSE "ENDIF" IF "$A" = "1" GOTO FXP ELSE "ENDIF" SLEEP 5 :WAT2 SetDefaultPrinter ("WAT02") GOTO "END" :RCH SetDefaultPrinter ("RCHINV") GOTO "END" :WTR1 SetDefaultPrinter ("watrst01") GOTO "END" :WTR2 SetDefaultPrinter ("watrst02") GOTO "END" :LBN SetDefaultPrinter ("lisbn") GOTO "END" :WBY SetDefaultPrinter ("wbay") GOTO "END" :NBR SetDefaultPrinter ("newber02") GOTO "END" :FXP SetDefaultPrinter ("foxpoint") GOTO "END" :END
ENDIF
printer.ini
;Printer configuration mapping file [Printers] WELGN=welgn01 LSBPRT=lsb01 Whitefishbay=wbay Newberlin=nbe01 Foxpoint=foxpoint BARTLETT=bart
|
|
Top
|
|
|
|
#19284 - 2002-04-02 10:08 PM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Do you have a specific question? Does it work? Have you tested it to see if the printer is set correctly? If it does not work, you may want to check @error after the ReadProfileString call. You do not a fully qualified path to the file and it may not be found as written. Where is the "rinter.ini" file located or should it be "printer.ini"? [ 02 April 2002, 22:11: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19285 - 2002-04-03 05:47 AM
Re: there has to be a better way
|
kdog
Fresh Scripter
Registered: 2002-02-19
Posts: 11
|
The rinter.ini was renamed for testing to see if it would error out at that point . I have tried running the script. It does not change the default printer. If I add a ? $printer to the script it states that variable has a value of zero at the end of the script. I will try using @lserver\netlogon\printer.ini to be more specific about the printer.ini location and see what happens with that . Thanks a ton for all of your assistance. Any other troubleshooting tips ?
|
|
Top
|
|
|
|
#19286 - 2002-04-03 06:02 AM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This may shed some light: code:
$Index = 0 $PrinterSet = 0 $NonPrinterGrps = "Domain Users,Domain Admins,Some Other Grps" $Domain = "@Ldomain\" ? "Domain=" + $Domain DO $Group = ENUMGROUP($Index) ? "Group[" + $Index + "]=" + $Group if instr($Group, $Domain) $Group = substr($Group,len($Domain)+1) if instr($NonPrinterGrps, $Group)=0 $file = "@lserver\netlogon\corp\printer.ini" if exist ($file) ? "Found $file" else ? "Error: file: $file not found" endif $Printer = ReadProfileString($file, "Printers", "$Group") ? @error @serror " ReadProfileString " + $Printer if $Printer <> "" $rc = SetDefaultPrinter ($Printer) ? "SetDefaultPrinter returned error code: " + $rc $PrinterSet = 1 endif else ? "Instr for NonPrinterGrps returned: " + instr($NonPrinterGrps, $Group) endif else ? "Instr for " + $Domain + " returned: " + instr($Group, $Domain) endif $Index=$Index+1 UNTIL $PrinterSet=1 or Len($Group) = 0
[ 03 April 2002, 06:41: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19287 - 2002-04-03 10:54 PM
Re: there has to be a better way
|
kdog
Fresh Scripter
Registered: 2002-02-19
Posts: 11
|
ok we are getting closer. I still honestly dont understand all the steps in this script but I am working on that. The script does not seem to make it to the line where it reads the printer.ini . The other odd part is I know you have error coding built in but it never seems to display any of that . Any other ideas ?
|
|
Top
|
|
|
|
#19288 - 2002-04-03 11:10 PM
Re: there has to be a better way
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I have taken this off-line with kdog but will post the final results when things work. [ 03 April 2002, 23:12: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 874 anonymous users online.
|
|
|