Hi Brad,
A)
You may take a look at the link below
http://groups.google.com/groups?q=gr...ary+group&hl=e
n&lr=&ie=UTF-8&oe=UTF-8&selm=SiqJ6NO5 CHA.1536%40cpms ftngxa08.phx.gb l&rnum=3
Or use the sample
Function GetUserPrimaryG roup(ByVal user As DirectoryEntry) As String
Dim primaryGroupID As Integer = user.Properties ("primaryGroupI D").Value
Dim objectSid As Byte() = user.Properties ("objectSid").V alue
Dim escapedGroupSid As New System.Text.Str ingBuilder()
'Copy over everything but the last four bytes(sub-authority/RID)
'Doing so gives a the prefix SID for objects in the user's domain
Dim i As Integer
For i = 0 To (objectSid.Leng th - 4) - 1
escapedGroupSid .AppendFormat(" \{0:x2}", objectSid(i))
Next i
'Add the primaryGroupID( RID) to the escape string to build the SID of
the
primaryGroup
For i = 0 To 3
escapedGroupSid .AppendFormat(" \{0:x2}", primaryGroupID And &HFF)
'This is like primaryGroupID >>= 8; in C#
primaryGroupID = primaryGroupID / (2 ^ 8) 'Move on to the next byte
Next i
'Search the directory for a group with this SID
Dim searcher As New DirectorySearch er()
searcher.Filter = "(&(objectCateg ory=Group)(obje ctSID=" +
escapedGroupSid .ToString() + "))"
searcher.Proper tiesToLoad.Add( "distinguishedN ame")
Return CStr(searcher.F indOne().Proper ties("distingui shedName")(0))
End Function 'GetUserPrimary Group
B)
Add a reference ADO and run the sample below in VB.NET
Private Sub Command1_Click( ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArg s) Handles Command1.Click
Dim cn As ADODB.Connectio n
Dim rs As ADODB.Recordset
cn = New ADODB.Connectio n
cn.Provider = "ADsDSOObje ct"
cn.Open()
rs = cn.Execute("sel ect AdsPath,SAMAcco untName from
'LDAP://CN=Users,DC=far east,DC=corp,DC =microsoft,DC=c om' where
objectClass='us er' and objectCategory= 'person'")
While Not rs.EOF
System.Diagnost ics.Debug.Write Line(VB6.TabLay out(rs.Fields(" AdsPath").Value ,
rs.Fields("SAMA ccountName").Va lue))
rs.MoveNext()
End While
rs.Close()
cn.Close()
rs = Nothing
cn = Nothing
End Sub
If you have any concern on this question, please post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure!
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.