VB.NET LDAP connection, can't show OU=Users

2019-08-27 21:06发布

问题:

I have a problem with reading OU=Users from my test server 2008, but OU=People (I have created) works. Error, it shows me is:

This object not exist on server

Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory
Imports System.Text
Imports System

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ADVstup As New DirectoryEntry("LDAP://192.168.1.1/OU=People,DC=pokus,DC=local", "Administrator", "Administrator")
    Dim ADVyhledani As New DirectorySearcher(ADVstup)
    Dim vysledky As SearchResultCollection
    Dim vysledek As SearchResult

    vysledky = ADVyhledani.FindAll

    For Each vysledek In vysledky
        MessageBox.Show(vysledek.GetDirectoryEntry.Properties("sAMAccountName").Value)
    Next
End Sub
End Class

Any idea about the cause of the error?

回答1:

The answer is in another post LDAP Directory Entry in .Net - not working with OU=Users

This may seem silly and stupid, but the default tree setup in Active Directory is not OU=Users,dc=domain,dc=com but rather CN=Users,dc=domain,dc=com (Note the CN= not the OU= for Users.



标签: vb.net ldap