To check if the computer is in more than one default printer group, I'd like to count for the existence of more than one group starting with the string "DefPrinter_ " and send a message to an administrator and exit, not changing the current default printer.

I can't get this script to work. Putting my computer in two DefPrinter_ groups does not send a message and continues to set both as default, with the last one the default.

code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920

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
for each $grp In $WS.Groups
$GrpName = $grp.Name


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

if left($GrpName,11) = "DefPrinter_"
$defprinter = substr($GrpName,12)
$defprinter = join(split($defprinter,"_"),"\")

if count(left(GrpName,11) = "DefPrinter_") > 1
? "Computer already has default printer"
? "Check Computer is only in one DefPrinter group"
? "Printer not added!"
$rc=SendMessage(testpc, '@wksta is in more than one DefPrinter Group, please set to only one!!')
exit 0

else

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

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

endif

endif


;--- Add secondary printers ---

if left($GrpName,8) = "Printer_"
$printer = substr($GrpName,9)
$printer = join(split($printer,"_"),"\")

if not PriMapState("\\" + $printer)
? "Status - Printer not connected \\"+$printer
$S=AddPrinterConnection("\\" + $printer)
? "Status - Printer added \\"+$printer
? @serror
?
endif

endif

next

endif

edited to reflect $printer should be $defprinter in Default printer portion of script. Removed $ from in front of $count.

[ 13. October 2003, 04:44: Message edited by: tjcarst ]