#206942 - 2013-03-19 02:45 PM
Efficiency Question - Adding Printers based on computer name
|
syntax53
Fresh Scripter
Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
|
I consider myself an intermediate to advanced kixtart scripter, but I'm struggling with coming up with the most efficient way to tackle an upcoming challenge. At our school district we have really just started rolling out Windows 7 computers within the past year. Up until then we have been manually adding the network printers and then copying the printers to the default/other user profiles as needed. With windows 7 that is no longer possible. Up until now we have been using the work around of adding network printers as local printers that point to a server\share on the port. With an upcoming deployment we want to start doing it the "proper" way-- adding them on the fly at login. I'd like to avoid having to use active directory as I feel like that would be more of a burden then doing it via kix. Our users (teachers and students) float around to computers all over the building and to other buildings so all printers must be added by computer name / geographical location and not by users themselves.
We have around 3000 computers (not all of which will need to have specific default printers recorded, but lets say they do) spread out over 10 buildings, with about 10-20 network printers at each building. Each machine in a particular building would typically get all network printers installed with one of them set as the default.
So, with that long explanation out of the way, what would be the most efficient solution to my dilemma? Doing a bunch of searches turned up basically three methods: arrays, ini file, and AD group membership. The INI files seems to be the most efficient and this is my idea as of now--
One INI file called "printers_default.ini" and another called "printers_building.ini". In the default one would be a list of machines in sections with a default printer and possibly any extra special printers.
In the default ini would be something like--
[wrkstn-1]
default=\\server\printer
extra1=\\server\printer2
[wrkstn-2]
default=\\server\printer
This the the thing I am most worried about as this file will end up being very large. Our largest building has about 137 computers that would need to be in there, so I suppose what would be a little more efficient is to break the list up by building as well, e.g. printers_default_domainname.ini and then have specific domain computers and defaults in there. It would still be a little ugly as it would require manual searching / sorting / entry by technicians.
And then in the printers_building.ini (the file containing a list of printers that get added to every machine regardless) I would have--
[domainname]
printer1=\\server\printer1
printer2=\\server\printer2
printer2=\\server\printer2
[otherdomain]
printer1=\\server2\printer1
printer2=\\server2\printer2
printer2=\\server2\printer2
And then the kix code would be something along the lines of...
$dp = ReadProfileString("printers_default_" + @DOMAIN + ".ini", @WKSTA, "default")
IF @ERROR = 0 AND $dp <> ""
FOR EACH $key In Split(ReadProfileString("printers_default_" + @DOMAIN + ".ini", @WKSTA, ""), Chr(10))
IF $key <> ""
$addprinter = ReadProfileString("printers_default_" + @DOMAIN + ".ini", @WKSTA, $key)
IF $addprinter <> "" $ret = ADDPRINTERCONNECTION($addprinter) ENDIF
ENDIF
NEXT
FOR EACH $key In Split(ReadProfileString("printers_buildings.ini", @DOMAIN, ""), Chr(10))
IF $key <> ""
$addprinter = ReadProfileString("printers_buildings.ini", @DOMAIN, $key)
IF $addprinter <> "" $ret = ADDPRINTERCONNECTION($addprinter) ENDIF
ENDIF
NEXT
$ret = SETDEFAULTPRINTER($dp)
ENDIF
... Thoughts?
|
Top
|
|
|
|
#206943 - 2013-03-19 04:27 PM
Re: Efficiency Question - Adding Printers based on computer name
[Re: syntax53]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Our commercial logon script accomplishes something similar for several school environments by using a small, custom script add-on.
The idea is to uniquely identify the campus, building, and room. This can be done by any combination of AD Site, network subnet, Computer OU, or part of a workstation name. The last school system where this was deployed used AD Site for campus and the first 5 letters of the workstation name to ID the location by building and room. Our script uses value rewrite capabilities to dynamically replace all or part of a UNC path.
In this deployment, there were two tables in the INI file. One mapped the campus ID to a partial server name, and the second mapped the building/room to the remaining server name part and the printer name.
When the login script ran, the UNC path of &SITE:SITE-SERVER&&USER_PRT:PRINTER& is evaluated. The AD Site name is used to lookup a replacement value for the server. All servers have a consistent naming scheme, so a print server in the SITE NAME of Farnsworth would begin with "FWFPSP" (FarnsWorth FilePrintService Production). The table then replaces &SITE:SITE-SERVER& with "\\FWFPSP", the first part of a valid UNC path. There are often multiple print servers, so the identifier is not included yet.. this is only a partial server name.
The second macro is then replaced.. the "USER" part of the macro depends on some user-written code that takes the first 5 characters of the computer name. This provides the 2-character building and 3-digit room identification. This is looked up in the second table and replaced with the appropriate partial server name and printer name.
Imagine that the Farnsworth campus has 3 buildings - Fox (FX), Smyth (SY), and Williams (WM), and 3-digit rooms identify floor and room. Each building has a print server and each room has a printer. The printers are named for the location, something like PR-205 for the printer in room 205. The second macro would be replaced with "01\PR-205", so the complete UNC path for a printer in room 205 of the Fox building of the Farnsworth campus would be "\\FWFPSP01\PR-205". The computer name would have begun with "FX205" to identify the Fox building, room 205. The printer names don't have to identify the campus or building since the server name makes that clear. Of course, this can be adapted to any naming scheme.
This lookup and value replacement provides a lot of flexibility, needs only a single INI file, and is processed very quickly.
FYI - I've been maintaining and updating this login script for over 15 years now. One thing I'll tell you, especially with multiple locations, is that you want to minimize the size and number of INI files involved in the login process or performance can suffer dramatically. Our script can complete a complex array of mapping in just a few seconds, and our performance logs measure actions in ms.
Also, this script deals with printers using a "Default Eligible" concept. Each printer resource can be marked as "default eligible" or not. Using lookups, you can set this value based on many parameters, allowing selection of the most appropriate default printer. This selection can also be overridden with a local environment variable, useful when the instructor has a local printer (or printer in the teacher's lounge) for printing things that should not "accidentially" show up on the classroom printer.
---
Looking at your INI, you can't have "Printer2" listed multiple times. I'm assuming this is a copy/paste issue but want to be clear.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 229 anonymous users online.
|
|
|