Directory Services

Using COM Interop to Access ADSI

System.DirectoryServices redefines selected, commonly used data structures and constants that are provided in ADSI. However, during the transition between COM applications and managed code applications, there will be instances when you will want a managed code application to have access to the features provided by low-level ADSI structures or advanced interfaces. To provide this interoperability between the underlying ADSI and managed code, the Common Language Runtime has provided COM interop. You can use to access any ADSI feature. This topic describes how to use COM interop to access ADSI.

Setting up COM Interop in Your Application

  1. Open Visual Studio .NET and create a new project.
  2. From Project, select "Add References..." to open the Add Reference dialog.
  3. Select COM tab.
  4. Select Active DS Type Library from the list, as shown in the following diagram.

  5. Click OK to add the ADSI library.

The ADSI Library Reference will appear on Visual Studio .NET Solution Explorer window. Please see figure below.

Instead of a reference you can add a using statement to your application, as shown in the following code example.

[C#]
using ActiveDs;
[Visual Basic .NET]
Imports ActiveDs

If you do not add a reference or a using statement, you must add the fully-qualified name for the ADSI library as shown in the following code example.

ActiveDs.IADsSecurityDescriptor