[.NET Active Directory开发]根据NativeGuid获取DirectoryEntry实例

     今天写一篇关于使用.NET进行Active Directory开发方面的文章
 
大家都知道NativeGuidActive Directory中对象的唯一标识,那么如何通过这个GUID来获取(查询)到相应DirectoryEntry对象的实例呢?
    .NET Framework
中的DirectoryService命名空间下并没有直接提供相应的方法,不过可以通过以下方法来获取:
    
假设在Active Directory中有一个用户:
     DN
为:CN=user1,OU=办公室,DC=njgw,DC=com
     NativeGuid
为:a46cc1f54eaf8c428cda3753e59265f6
    
使用以下代码:
     DirectoryEntry entry=new DirectoryEntry();
     entry.Path =
LDAP://ServerAddress/<GUID=a46cc1f54eaf8c428cda3753e59265f6>;
     entry.Username="Administrator";
     entry.Password="Administrator_Password";
    
即可获取到该用户的DirectoryEntry实例,怎么样?是不是比使用DirectorySearcher更方便、更准确呢?

posted @ 2007-07-04 21:22  Francis Liang  阅读(3196)  评论(6编辑  收藏  举报