VB.Net - Active Directory

Active Directory

Here is a sample of how to get all the information about a person stored in the active directory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' disect

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://MSSA/CN=Coben. Ralf (MSA),OU=Users,OU=Campus - Bsw,DC=pwa,DC=sacKnty,DC=net")
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult

Dim AttrName As String
Dim objValue As Object
'For Each AttrName In anActiveDir.Properties.PropertyNames
' For Each objValue In anActiveDir.Properties(AttrName)
' Console.WriteLine(AttrName & " : " & objValue.ToString)
' Next
'Next

'Dim anActiveDir As DirectoryServices.DirectoryEntry _
' = New DirectoryServices.DirectoryEntry("WinNT://PWA")
For Each AttrName In entry.Properties.PropertyNames
For Each objValue In entry.Properties(AttrName)
Console.WriteLine(AttrName & " : " & objValue.ToString)
Next
Next

MsgBox("done")

End Sub

Common Errors

Active Directory Error - System.Runtime.InteropServices.COMException (0x80072020):
An operations error occurred at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at …

I see this happen on a web site.
When I have the site configured as NT Authentication - I get the error
When I have the site configured as basic authentication

  • the error goes away. If you really want to run the site with NT Authentication …