WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

OLE COM dsGetMemGrps Alternative


Simple Example:

usr = GetObject(UserPath) ;Pass this the same thing you passed dsGetUsersGrps
groups = ""
ForEach grp In usr.Groups
    groups = StrCat(groups, @TAB, grp.Name)
Next
AskItemlist("Groups user is member of", groups, @TAB, @UNSORTED, @SINGLE)
usr = 0

Better example using ADSI Extender:

AddExtender("wwads44i.dll")

; Probably will not work as is across domains.

#DefineFunction GetAllGroups(strServer, strObjPath, plAllGroups)

   ; Look for a nested group.
   lMembership = dsGetProperty(strObjPath, "memberOf")
   nMemberOfs = ItemCount( lMembership, @TAB)
   For i = 1 To nMemberOfs

      ; Get the next group.
      strPath = ItemExtract(i, lMembership, @TAB)
      strPath = strServer:"/":strPath

      ; Check for tombstones.
      If dsIsObject(strPath)

         ; Prevent duplicates and infinity
         If ItemLocate(strPath, *plAllGroups, @TAB) Then Continue

         ; Add to group list
         *plAllGroups = ItemInsert(strPath, -1, *plAllGroups, @TAB)

         ; Add groups memeber to list
         GetAllGroups(strServer, strPath, plAllGroups)
      EndIf
   Next

   Return 1
#EndFunction

; Set values by method of choice.
strServer  = "LDAP://shamrock" ; Our test server
strUserSam = "rrabbit"          ; A test user with convoluted group membership.
lAllGroups = ""

; Get the full path.
strUser = dsFindPath(strServer, "(&(objectCategory=person)(sAMAccountName=%strUserSam%))")
If strUser == ""
   Message("Blah Blah Blah", "Bad user SAM name")
   Exit
EndIf

; Get regular groups
GetAllGroups(strServer, strUser, &lAllGroups)

; Get Primary group when necessary.
strPrimGroup = dsGetPrimGrp(strUser)
If !ItemLocate( strPrimGroup, lAllGroups, @TAB )
   lAllGroups   = ItemInsert(strPrimGroup, -1, lAllGroups, @TAB)
   GetAllGroups(strServer, strPrimGroup, &lAllGroups)
EndIf

Message("All Groups", lAllGroups)


Article ID:   W16815
File Created: 2011:02:17:16:23:56
Last Updated: 2011:02:17:16:23:56