Okay I have re-created the printer groups after modifying the script. I now have updated the script that maps the printers based upon the printer groups.
I would like to know if there is a way to map the printer group name code to a server name without re-writing this code for each combination. An Array? This would remove the hard coded A01, PS1, in my script.
For example print server names
PS1=MRH-01
PS2=MRH-02
Printer group names
D01=Default printer on PS1
D02=Default printer on PS2
A01=Default printer on PS1
A02=Default printer on PS2
etc.
code:
call @ScriptDir+'\PriMapState.udf'
;********** Prevent script from running on a server or Win95*********
if @userid = administrator
call @Scriptdir+'\osid.udf'
$os=osid()
if $os[1]='Win95' or $os[2]<>'Workstation'
exit 0
endif
endif
;********** Prevent script from running on Medrec pcs *********
if InGroup ("Medrec Group")
exit 0
endif
;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")
if @error
? @serror
else
$ps1="mrh-01"
for each $grp In $WS.Groups
$GrpName = $grp.Name
;--- 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
; $rc=PriMapState($defprinter)
; ? $rc
; if $rc<>2
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set " + $defprinter
? @serror ?
else
exit 0
endif
endif
endif
;--- Add additional printers ---
if left($GrpName,4) = "A01_"
$addlprinter = substr($GrpName,5)
$addlprinter = $ps1+"\"+$addlprinter
$addlprinter = "\\"+$addlprinter
? "Additional printer(s): "$addlprinter
if not PriMapState($addlprinter)
? "Status: Printer not connected " + $addlprinter
$S=AddPrinterConnection($addlprinter)
? "Status: Printer added " + $addlprinter
? @serror ?
endif
endif
next
endif
[ 27. October 2003, 18:28: Message edited by: tjcarst ]