2009-11-17 86 views
0

C#的新手。我正在尝试浏览AD的特定OU。我收到以下错误。错误代码2147016646.我试着用更高的privl运行程序。 ACCT。但仍然有同样的错误。活动目录服务器不可操作。错误代码2147016646

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.DirectoryServices; 
using System.DirectoryServices.ActiveDirectory; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 
      string objectPath = "Server1"; 
      try 
      { 
       if (DirectoryEntry.Exists("LDAP://" + objectPath)) 
        Console.WriteLine(objectPath + "exists"); 
       else 
        Console.WriteLine(objectPath + " does not exists"); 
      } 
      catch (DirectoryServicesCOMException e) 
      { 
       Console.WriteLine(e.Message.ToString()); 
      } 
     }  
    } 
} 

回答

1

您可能必须为LDAP路径使用的不仅仅是“Server1”。

尝试类似:

string objectPath = "Server1/cn=Users,dc=yourcompany,dc=som"; 
try 
{ 
    if (DirectoryEntry.Exists("LDAP://" + objectPath)) 
     Console.WriteLine(objectPath + "exists"); 
    else 
     Console.WriteLine(objectPath + " does not exists"); 
} 

如果你的服务器上默认的“用户”容器存在(或不)这将检查。

马克

-3

强烈推荐 “的.NET开发人员指南与目录服务编程” ISBN 0-321-35017-0

值得其重量的黄金!

+0

对于这里提出的具体问题,推荐一本书并不是什么回答。 – 2011-07-07 15:45:15