Hello all, I've got a situation where I was hoping I could get some expert advice on how to fix it and/or just make it better.
I've only just started with kix a few days ago so I'm still just trying to get my feet wet. We've been having printer mapping issues at my new job and looking into the script, it was a complete mess so I'm trying to rewrite it.

Here's a part of the print.kix I'm planning on using to unmap and then map printers with ini. After pouring over the forum, using an ini seems like a good solid method considering the original script was just tons of case statments and if ingroups.

 Code:
 
Function UnmapPrinters() 
Dim $bk,$conn 
 $bk="HKEY_CURRENT_USER\Printers\Connections" 
 Do
  $conn=DelKey($bk+"\"+EnumKey($bk,0))
 Until @error
EndFunction

? "Unmapping printers...."
UnmapPrinters
? "Errors:"
@SERROR
;DelPrinterConnection ("")
;@SERROR
? "Done..."

$ID = Left(@WKSTA, 4)
$PrinterList = Split(ReadProfileString('C:\printers.ini', $ID, 'Printers'), ';')
$DefPrinter = ReadProfileString('C:\printers.ini', $ID, 'Default')
For Each $Printer in $PrinterList
	AddPrinterConnection($Printer)
Next
SetDefaultPrinter($DefPrinter)



Another part of the original script, and the part where I'm having problems is below. Basically we just have to create a printer (and we have hundreds) and make a matching print-printername and a printd- printername AD group. That sets their printers and default that way. I like that a lot since we do have roaming users and lots of onesies we have to setup.

What I'd like to do is start with the script at the top to set a bunch of dept printers but also have the ability to use the print groups already established to cover the one-offs. The part that I can't wrap my head around is to eliminate the redundancy of remapping printers that will already be in the users groups (because lots of users are already members of several print groups) and that have already just been mapped by the ini. It might be fine the way it is if we just clean up the print groups now and there won't be too much remapping happening, but I'll leave that up to any experts to decide

 Code:
 
;set index to 0 for looping through groups
$LoopIndex = 0

;get first group name
$UsersGroups = ENUMGROUP($Index)

;loop
DO
;if group name is longer than nothing
	if Len($UsersGroups) > 0

		;if group name starts with print
		if lcase(substr($UsersGroups, 1, 14)) = "westcare\print"
			
			;if group is a printd group, add first
			if lcase(substr($UsersGroups, 1, 16)) = "westcare\printd-"
				
				;add printer and make sure it’s successful
				if addprinterconnection('\\wcps1\' + lcase(substr($UsersGroups, 17))) = 0

					;display success message
					? "Added printer: " + substr($UsersGroups, 17)
				else
					;display error message and text
					? "Error Adding Printer: " + substr($UsersGroups, 17)
					? "Error: " + @SERROR
				endif

				;set default printer to group name after add
				if setdefaultprinter('\\wcps1\' + substr($UsersGroups, 17)) = 0
	
					;display success message.	
					? "Set default printer to: " + substr($UsersGroups, 17)
				Else
					;display error message and text
					? "Error Setting Default Printer: " + substr($UsersGroups, 17)
					? "Error: " + @SERROR
				EndIf
			else	
				;add printer if just a print- group
				if addprinterconnection('\\wcps1\' + lcase(substr($UsersGroups, 16))) = 0

					;display success message
					? "Added printer: " + substr($UsersGroups, 16)
				else
					;display error message and text
					? "Error Adding Printer: " + substr($UsersGroups, 16)
					? "Error: " + @SERROR
				endif			
			endif
		EndIf
	EndIf
	
;increase the loop counter by 1
$LoopIndex = $LoopIndex + 1

;get next group name
$UsersGroups = ENUMGROUP($LoopIndex)

;loop until end of groups list
UNTIL Len($UsersGroups) = 0



Thanks for taking a look guys and I look forward to any and all advice. And thank you for a great forum. I've learned a lot just from reading here, and credits to anyone I borrowed bits or pieces from code to make it work for me.

BR