;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       fInGroup() 
;; 
;;ACTION         Checks 1 or more groups for membership by the current user 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2013/09/17 
;; 
;;HISTORY        1.0  - 2013/09/17 - Initial Release 
;; 
;;SYNTAX         fInGroup(Group[, Group2...] 
;; 
;;PARAMETERS     Group - REQUIRED, String List - A comma-delimited list of groups to check 
;;               for membership.  
;; 
;;REMARKS        Uses EnumGroup to create a list of groups, then augments that list using LDAP. 
;;                
;; 
;;RETURNS        Boolean - Returns true if the user is a member of any of the listed groups. 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    WXP, W2K3, Vista, Win7, W2K8, W2K12 
;; 
;;EXAMPLES       ; Map a drive if a member of either group 
;;               If fInGroup('RC_Share1,RC_Share1_RO') 
;;                 Use G \\server\share1 
;;               EndIf 
; 
Function fInGroup($_Group)
 
  Dim $_I						; Index Var 
  Dim $_C						; Count of matched groups 
  Dim $_oSys, $_oTarget					; Connection Objects 
  Dim $_aMemberOf, $_MemberOf				; Array of groups, enumerator 
  Dim $_aGroups						; array of groups that the user is a member of 
 
 
  $fInGroup = 0						; default FALSE 
  $_C = -1						; no memberships 
 
  $_I = -1
/*
  Do
    $_I = $_I + 1
    ReDim Preserve $_aGroups[$_I]
    $_aGroups[$_I] = EnumGroup($_I)
    If InStr($_aGroups[$_I], '\')
      $_aGroups[$_I] = Split($_aGroups[$_I], '\')[1]
    EndIf
  Until EnumGroup($_I) = ''

  $_I = $_I - 1
 */
 
  $_oSys = CreateObject('ADSystemInfo')			; instantiate connection 
  $_oTarget = GetObject('LDAP://' + $_oSys.UserName)	; Connect to AD 
  $_aMemberOf = $_oTarget.GetEx('memberOf')		; Get list of groups 
  For Each $_MemberOf in $_aMemberOf
    $_MemberOf = Split(Split($_MemberOf, '=')[1], ',')[0]
    If AScan($_aGroups, $_MemberOf) = -1
      $_I = $_I + 1
      ReDim Preserve $_aGroups[$_I]
      $_aGroups[$_I] = $_MemberOf
    EndIf
  Next
 
  $_aInGroups = Split($_Group, ',')
  For Each $_Group in $_aInGroups
    If AScan($_aGroups, $_Group) > -1
      $_C = $_C + 1
    EndIf
  Next
 
  If $_C > -1 $fInGroup = 1 EndIf
  Exit Not $fInGroup
 
EndFunction