/// <summary> /// 将组移动到组织单元上 /// </summary> /// <param name="cn"></param> /// <param name="parentcn"></param> public int MoveGroupToUnit(string cn, string ou, string ouPath, out string errStr) { int result = 0; errStr = ""; string LDAPDomain = "/" + ouPath.ToString() + Iadc.GetLDAPDomain(); LDAPDomain = ouPath; DirectoryEntry oDE = Iads.GetUnitEntry(ou, LDAPDomain.Substring(18)); DirectoryEntry oDEC = Iads.GetGroupEntry(cn); if (!Iadch.CheckGroup(cn)) { return(2); } try { oDEC.MoveTo(oDE); oDE.CommitChanges(); result = 1; } catch (Exception err) { result = 0; errStr = err.ToString(); } finally { oDEC.Close(); oDE.Close(); } return(result); }
/// <summary> /// 在指定的组织单元下创建新的组织单元 /// </summary> /// <param name="father_OU">父单元路径:格式(OU=father_OU_1,OU=father_OU_2,)</param> /// <param name="childer_OU">子单元</param> /// <returns></returns> public int EditUnitName(string OU, string path, string newName, out string errStr) { int result = 0; errStr = ""; string LDAPDomain = "/" + path.ToString() + Iadc.GetLDAPDomain(); DirectoryEntry oDEC = Iads.GetUnitEntry(OU, LDAPDomain); if (!Iadch.CheckUnit(OU)) { return(2); } try { oDEC.Properties["l"].Value = "3"; oDEC.Properties["description"].Value = newName; result = 1; oDEC.CommitChanges(); } catch { result = 0; errStr = "Err0001"; //未指定错误 } finally { oDEC.Close(); } return(result); }
/// <summary> /// 将用户移动到容器 /// </summary> /// <param name="cn">UserName</param> /// <param name="ou">容器</param> public int MoveUserToUnit(string cn, string ou, string father_OU, out string errStr) { int result = 0; errStr = ""; string LDAPDomain = "/" + father_OU.ToString() + Iadc.GetLDAPDomain(); DirectoryEntry oUnit = new DirectoryEntry(); DirectoryEntry oUser = new DirectoryEntry(); if (!Iadch.CheckUnit(ou)) { errStr = "未找到指定的机构/部门"; return(3); } if (!Iadch.CheckUser(cn)) { errStr = "未找到指定的用户"; return(2); } try { oUnit = Iads.GetUnitEntry(ou, LDAPDomain); oUser = Iads.GetUserEntry(cn); if (!oUnit.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value)) { oUser.Properties["l"].Value = "4"; oUser.MoveTo(oUnit); oUser.CommitChanges(); oUnit.CommitChanges(); result = 1; } } catch (Exception err) { result = 0; } finally { oUser.Close(); } return(result); }