After much work and assistance from users her, I have a script that adds printers to computers based upon computer groups. Search the Starters forum for more details.

I had the printer names already defined by q-<name> format in my domain. (I used a kix script to create all the corresponding group names in the format of A01_<printername> and D01_<printername>. If you are interested in this script, let me know.)

To save login time for those users not receiving printers based upon group membership, I created an additional group called Printer Setup Group and added the workstations to this group that will be receiving printers based upon group membership and call the script printers.kix that I am posting here only if workstations are in this first group. I use the function ComputerInGroup.udf to determine if workstations are in the Printer Setup Group, for example, in my kixtart.kix login script I include the following:

Code:

if ComputerInGroup ('Printer Setup Group')=1
call @ScriptDir+'\printers.kix'
endif



This script will not work for Windows 95. Note that it calls the function PriMapState.udf.

Syntax of names:

Printer names = <q-name>

Computer Group names for default printer = D01_<printername>

Computer Group names for add'l printer = A01_<printername>

Print Server name = srv-01 (specified by variable ps1$)

For example, to add default printer q-printer1 and additional q-printer2 shared on server srv-01 to a computer named computer1:

1. Printers shared from server srv-01 = \\srv-01\q-printer1 and \\srv-01\q-printer2
2. Create a group called D01_q-printer1
3. Create a group called A01_q-printer2
4. Add computer1 to both groups
5. Login from computer1

If the printers do not exist, they will be added as q-printer1 as default and q-printer2 as additional. If they exist but wrong the one is default, it will be changed to printer as specified by D01_ group.

Printers.kix
Code:

;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")

if @error
? @serror
else

$ps1="srv-01"

for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add additional printers ---

if left($GrpName,4) = "A01_"
$addlprinter = substr($GrpName,5)
$addlprinter = $ps1+"\"+$addlprinter
$addlprinter = "\\"+$addlprinter
? "Additional Printer: "$addlprinter

if not PriMapState($addlprinter)
? "Status: Printer not connected " + $addlprinter
$S=AddPrinterConnection($addlprinter)
? "Status: Printer added: " + $addlprinter
? @serror ?

endif

endif

;--- Add and set default printer ---

if left($GrpName,4) = "D01_"
$defprinter = substr($GrpName,5)
$defprinter = $ps1+"\"+$defprinter
$defprinter = "\\" + $defprinter
? "Default Printer: "$defprinter

if not PriMapState($defprinter)
? "Status: Printer not connected "+$defprinter
$nul=AddPrinterConnection($defprinter)
? "Status: Printer added "+ $defprinter
? @serror ?
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set: " +$defprinter
? @serror ?
endif

if PriMapState($defprinter)<>2
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set: " + $defprinter
? @serror ?
?
endif

endif

next

endif

;FUNCTION PriMapState v1.1
;
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;
;ACTION Checks for existent networkprinter connection
;
;SYNTAX PriMapState(PRINTER)
;
;PARAMETERS PRINTER
; Printers name to be checked
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;
;REMARKS code for w9x adapted from BrianTX
;
;DEPENDENCIES none
;
;EXAMPLE if not PriMapState('\\server\printer1')
; "printer not connected!"
; endif
;
;CODE
function PriMapState($_Pri)
if @inwin=1
if len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
if split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri
$PriMapState=2
else
$PriMapState=1
endif
endif
else
dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
for $_C=0 to 259
$_C2=enumkey($_Root,$_C)
If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
$PriMapState = 2
Else
$PriMapState = 1
Endif
Endif
if $_C2=259 $_C=$_C2 endif
next
endif
endfunction




Edited by tjcarst (2004-01-20 08:14 PM)