/// <summary> /// 编辑AD中已经注册的当前用户信息 /// </summary> /// <param name="loginName">当前用户的登录名</param> /// <param name="displayName">当前用户的显示名</param> /// <param name="email">当前用户的电子邮件</param> /// <param name="mobile">当前用户的手机号码</param> /// <returns>T/F</returns> public static bool EditUser(string loginName, string displayName, string email, string mobile, string groupName, string userDep = "") { DirectoryEntry currentUser = ADHelper.GetDirectoryEntryByAccount(loginName);//当前被编辑的用户 currentUser.Properties["displayName"][0] = displayName; //currentUser.Properties["name"][0] = displayName;//执行此句会出现错误 if (mobile != "") { if (currentUser.Properties.Contains("telephoneNumber")) { currentUser.Properties["telephoneNumber"][0] = mobile; } else { currentUser.Properties["telephoneNumber"].Add(mobile);//家庭电话otherTelephone } } else if (currentUser.Properties.Contains("telephoneNumber")) { currentUser.Properties["telephoneNumber"].RemoveAt(0); } if (email != "") { if (currentUser.Properties.Contains("mail")) { currentUser.Properties["mail"][0] = email; } else { currentUser.Properties["mail"].Add(email); } } else if (currentUser.Properties.Contains("mail")) { currentUser.Properties["mail"].RemoveAt(0); } if (userDep != "") { if (currentUser.Properties.Contains("department")) { currentUser.Properties["department"][0] = mobile; } else { currentUser.Properties["department"].Add(mobile);//手机号码 } } else if (currentUser.Properties.Contains("department")) { currentUser.Properties["department"].RemoveAt(0); } if (groupName != "") { AddUserToSafeGroup(loginName, groupName); } try { currentUser.CommitChanges(); return(true); } catch (Exception ex) { return(false); } }