The Standard Method

There is not much more to say here. In this case, we just create a runtimecallable wrapper (RCW) interop assembly for the entire activeds.tlb type library using tlbimp.exe or Visual Studio .NET. For Visual Studio .NET, this is as simple as using Project > Add Reference and selecting activeds.tlb from the COM tab. If we are not using Visual Studio .NET, we need to use the command-line tool from the .NET SDK, called tlbimp.exe. Here is a sample command line for using this tool (watch for the wrap):

tlbimp.exe activeds.tlb /out:activedsNET.dll

This will create an RCW called activedsNET.dll that we should deploy with our application. If necessary, we can also provide a strong name for the generated assembly so that we can call it from our own strong-named assemblies as well. The .NET runtime includes a security restriction that prevents strongly named assemblies from calling into assemblies that are not strongly named. For more information about code access security (CAS) policy as it relates to strong names, see Chapter 8.


The advantages of this approach are that it is easy and the performance is good.


The downsides of this approach are as follows.

  • We have an extra assembly to deploy with our code all the time.
  • We may not like the way the default conversion renders some of the ADSI types. For example, none of the enumerations that can be combined bitwise has the FlagsAttribute attribute applied to it, and the IDirectorySearch and IDirectoryObject interfaces are not really useful with the default conversion.

Because of the ease of use of this approach, we have tended to use it throughout the book, even though it might not be ideal for all situations.

Microsoft could actually improve on the second point by providing what is called a Primary Interop Assembly (PIA) for activeds.dll, similar to what it does with the Microsoft Office automation libraries, which is handcrafted to address these problems and includes a strong name. However, Microsoft has thus far not elected to do this for us.

Part I: Fundamentals

Introduction to LDAP and Active Directory

Introduction to .NET Directory Services Programming

Binding and CRUD Operations with DirectoryEntry

Searching with the DirectorySearcher

Advanced LDAP Searches

Reading and Writing LDAP Attributes

Active Directory and ADAM Schema

Security in Directory Services Programming

Introduction to the ActiveDirectory Namespace

Part II: Practical Applications

User Management

Group Management


Part III: Appendixes

Appendix A. Three Approaches to COM Interop with ADSI

Appendix B. LDAP Tools for Programmers

Appendix C. Troubleshooting and Help


The. NET Developer's Guide to Directory Services Programming
The .NET Developers Guide to Directory Services Programming
ISBN: 0321350170
EAN: 2147483647
Year: 2004
Pages: 165 © 2008-2020.
If you may any questions please contact us: