DirectoryServices.SearchResult

  • VB.NET
  • .NET (FX) 4.5–4.8

    DirectoryServices.SearchResult

    Hallo,

    ich hab mal wieder ein Problem,

    die Idee erstmal. Ich möchte aus der ActiveDirectory die User namen , die Durchwahl und die E-Mail Adresse auslesen, das funktioniert soweit auch gut.

    Die Ergebnisse werden mir Zeilenweise ausgegeben.

    Aber:

    Wenn z.B ein user keine Durchwahl hat wird an dieser stelle die Suche abgebrochen, ich Probiere jetzt schon einige Zeit rum, aber ohne Erfolg.

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim UserID As String
    2. Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://EINEIP")
    3. Dim DomainDN As String = CType(RootDSE.Properties("DefaultNamingContext").Value, String)
    4. Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://HIERKÖNNTEIHREWERBUNGSTEHEN" & DomainDN)
    5. Dim objSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
    6. Dim oResults As DirectoryServices.SearchResultCollection
    7. Dim oResult As DirectoryServices.SearchResult
    8. Dim i As Integer
    9. i = 1
    10. UserID = "*."
    11. objSearch.Filter = "(& (objectClass=Person)(cn=*" & "))"
    12. oResults = objSearch.FindAll
    13. For Each oResult In oResults
    14. If oResult.GetDirectoryEntry.Properties("telephoneNumber").Value IsNot Nothing _
    15. And oResult.GetDirectoryEntry.Properties("cn").Value IsNot Nothing _
    16. And oResult.GetDirectoryEntry.Properties("mail").Value IsNot Nothing _
    17. And oResult.GetDirectoryEntry.Properties("mobile").Value IsNot Nothing Then
    18. ListBox1.Items.Add(oResult.GetDirectoryEntry.Properties("telephoneNumber").Value.ToString() & " " _
    19. & oResult.GetDirectoryEntry.Properties("cn").Value.ToString() & " " _
    20. & oResult.GetDirectoryEntry.Properties("mail").Value.ToString() _
    21. & oResult.GetDirectoryEntry.Properties("mobile").Value.ToString())
    22. i = i + 1
    23. End If
    24. Next
    25. '** Wir bringen den Müll weg **
    26. GC.Collect()
    27. Catch ex As Exception
    28. Return
    29. End Try


    Also an der Stelle wenn der Rückgabe wert quasi 0 ist, aus dem Feldnamen telephoneNumber oder eben mobil, soll er dennoch weiter suchen. CN wenn keiner mehr da ist kann er ja aufhören zu suchen ^
    Für einen Tipp währe ich sehr dankbar


    oh man.. fast schon peinlich, habs hinbekommen .. :)

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Blackn0va“ ()