public Boolean ValidateDomainUser(string Domain, string UserName, string Password) { DirectoryEntry entry = new DirectoryEntry(Domain, UserName, Password); try { string objectSid = (new SecurityIdentifier((byte[])entry.Properties["objectSid"].Value, 0).Value);//如果账号不对则会抛出异常 return true; } catch { return false; } finally { entry.Dispose(); } } //代码调用,LDAP一定要大写。 MessageBox.Show(ValidateDomainUser("LDAP://域控的IP地址/DC=ha-ad,DC=net", "evan", "evan的密码").ToString());