Skip to Content
Active Directory Cookbook
book

Active Directory Cookbook

by Robbie Allen
September 2003
Intermediate to advanced
624 pages
15h 49m
English
O'Reilly Media, Inc.
Content preview from Active Directory Cookbook

18.2. Programming with .NET

Problem

You want to programmatically access Active Directory using the .NET Framework.

Solution

The System.DirectoryServices namespace can be used to interface with Active Directory using the .NET Framework. The following code is a simple VB.NET program that prints the attributes of the RootDSE:

Imports System.DirectoryServices

Module Module1

    Sub Main( )

        Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")

        Dim strAttrName As String
        Dim objValue As Object

        For Each strAttrName In objRootDSE.Properties.PropertyNames
            For Each objValue In objRootDSE.Properties(strAttrName)
                Console.WriteLine(strAttrName & " : " & objValue.ToString)
            Next objValue
        Next strAttrName

    End Sub

End Module

Discussion

The System.DirectoryServices namespace is a generic directory service interface that is intended to replace ADSI. It provides a rich set of properties and methods for accessing, querying, and manipulating objects in Active Directory. Currently, there is no native support for scripting languages, such as VBScript and Perl, but you can use Microsoft’s version of JavaScript (i.e., JScript) with .NET to utilize System.DirectoryServices.

The System.DirectoryServices DirectorySearcher class is a simple interface for making LDAP queries. The DirectoryEntry class is used for instantiating existing objects or creating new ones. In the Solution section, I used the DirectoryEntry class to access the RootDSE. DirectorySearcher and DirectoryEntry are the two main classes to become familiar ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Active Directory Administration Cookbook

Active Directory Administration Cookbook

Sander Berkouwer
Active Directory Cookbook, 3rd Edition

Active Directory Cookbook, 3rd Edition

Laura E. Hunter, Robbie Allen
Active Directory Cookbook, 4th Edition

Active Directory Cookbook, 4th Edition

Brian Svidergol, Robbie Allen

Publisher Resources

ISBN: 0596004648Supplemental ContentCatalog PageErrata