域是域,局域网是局域网,切勿混淆RT,求具体代码

解决方案 »

  1.   

    DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com");
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = "(&(objectClass=user)(anr=test*))";
    SearchResultCollection ResEnt = mySearcher.FindAll();
    {
    // Handle results.
    }
    // Handle exceptions.
      

  2.   

                if (runcmd("net user /DOMAIN").IndexOf("nattystyle") >= 0)
                    Console.WriteLine("Has user");
                else
                    Console.WriteLine("No user");没有域环境,你试试.不行算我没说.        private static string runcmd(string command)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = "/c " + command;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                return p.StandardOutput.ReadToEnd();
            }
      

  3.   

    //1. add reference System.DirectoryServices...
    using System.DirectoryServices
    ...
    ...
    public static bool DoesDomainUserExist(string username)
    {
       DirectoryEntry entry = new DirectoryEntry("LDAP://YourDomain","yourDomainUserName", "yourDomainPassword" );  
       DirectorySearcher searcher = new DirectorySearcher(entry);
       searcher.Filter = "(&(objectClass=user) (cn=" + username + "))";
       SearchResultCollection results = searcher.FindAll(); 
       return results.Count > 0;
    }
      

  4.   

    以前做过类似的程序,直接copy过来给你。