habs jezz mit hilfe von nem kollegen hier hinbekommen...
hier das ganze prüllding
Code:
Imports System.DirectoryServices
PublicClass Form1
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim usr AsString = Environment.UserName
Dim dom AsString = Environment.UserDomainName
Dim deUser As DirectoryServices.DirectoryEntry = getUser(usr, True)
ForEach m AsStringIn deUser.Properties("memberof").Value
Dim deGroup AsNew DirectoryEntry("LDAP://" & m)
Me.ListView1.Items.Add(deGroup.Name)
Next
EndSub
PublicFunction getUser(ByVal pstrUsername$, OptionalByVal bFromSAM AsBoolean = False) As DirectoryServices.DirectoryEntry
getUser = Nothing
IfNot bFromSAM Then
Try
Dim objADSystemInfo As ActiveDs.ADSystemInfo
objADSystemInfo = CreateObject("ADSystemInfo")
getUser = New DirectoryServices.DirectoryEntry("LDAP://" & objADSystemInfo.DomainDNSName)
Dim sUser AsNew DirectoryServices.DirectorySearcher(getUser, _
"(&(objectclass=user)(anr=" & pstrUsername & "))", _
Nothing, DirectoryServices.SearchScope.Subtree)
getUser = sUser.FindOne.GetDirectoryEntry
Catch ex As Exception
EndTry
Else
Try
Dim objADSystemInfo As ActiveDs.ADSystemInfo
objADSystemInfo = CreateObject("ADSystemInfo")
getUser = New DirectoryServices.DirectoryEntry("LDAP://" & objADSystemInfo.DomainDNSName)
Dim sUser AsNew DirectoryServices.DirectorySearcher(getUser)
sUser.Filter = "(&(objectclass=user)(SAMAccountName=" & pstrUsername & "))"
sUser.PropertiesToLoad.Clear()
sUser.PropertiesToLoad.Add("SAMAccountName")
sUser.SearchScope = SearchScope.Subtree
getUser = sUser.FindOne.GetDirectoryEntry
Catch ex As Exception
ReturnNothing
EndTry
EndIf
EndFunction
EndClass