110,539
社区成员
发帖
与我相关
我的任务
分享
private void button4_Click(object sender, EventArgs e)
{
DirectoryEntry domain = new DirectoryEntry();
string domainName = "gzxinxi.com";
domain.Path = string.Format("LDAP://{0}", domainName);
domain.Username = "jiankong";
domain.Password = "jiankong";
domain.AuthenticationType = AuthenticationTypes.Secure;
domain.RefreshCache();
string commonName = textBox2.Text.Trim().ToString();
DirectorySearcher deSearch = new DirectorySearcher(domain);
deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(cn=" + commonName + "))";
SearchResult results = deSearch.FindOne();
if (results != null)
{
DirectoryEntry user = results.GetDirectoryEntry();
string first = "总公司";
string second = "部门1";
string third = "综合部";
string fourth = "党群";
string all = "LDAP://DC=gzxinxi,DC=com,OU=党群,OU=综合部,OU=部门1,OU=总公司";
user.MoveTo(new DirectoryEntry(all));
MessageBox.Show("成功");
}
else
{
MessageBox.Show("失败");
}
}