/// <summary> /// 添加新组到指定的组织单元 /// </summary> /// <param name="cn">用户组</param> /// <param name="ouPath">组织单元路径(格式:OU=sddsd,OU=sdsdsd,顺序,子倒父)</param> /// <param name="description">描述</param> /// <returns>bool</returns> public int CreateGroupToUnit(string cn, string description, string path, out string errStr) { int result = 0; errStr = ""; //创建指定路径的组织单元对象 int i = 0; int j = 0; //string LDAPDomain ="/"+ouPath.ToString()+Iadc.GetLDAPDomain() ; //string LDAPDomain ="/"+ouPath.ToString()+ Iadc.GetLDAPDomain() ; //DirectoryEntry oDE= Iadc.GetDirectoryObject(LDAPDomain); DirectoryEntry oDE = Iadc.GetDirectoryObject(Iads.GetUnit(cn).ToString(), i, j); //DirectoryEntry oDE= Iadc.GetDirectoryObject(ouPath); DirectoryEntry oDEC = new DirectoryEntry(); try { if (!Iadch.CheckGroup(cn)) { oDEC = oDE.Children.Add("cn=" + cn, "group"); //oDEC.Properties["grouptype"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP | ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED ; oDEC.Properties["sAMAccountName"].Value = cn; oDEC.Properties["description"].Value = description; oDEC.Properties["displayName"].Value = path; oDEC.CommitChanges(); result = 1; } else { //移动组到正确的OU中 oDEC = Iads.GetGroupEntry(cn); oDEC.Properties["displayName"].Value = path; oDEC.CommitChanges(); oDEC.MoveTo(oDE); oDE.CommitChanges(); result = 2; errStr = "目录已存在该组,不能重复添加"; } } catch (Exception err) { result = 0; errStr = err.ToString(); } finally { oDE.Close(); oDEC.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 DeleteUnitOnState2(string OU, out string errStr) { int result = 0; errStr = ""; // string LDAPDomain ="/"+path.ToString()+ Iadc.GetLDAPDomain() ; //DirectoryEntry oDEC=Iads.GetUnitEntry(OU,LDAPDomain); DirectoryEntry oDEC = new DirectoryEntry(); oDEC = Iadc.GetDirectoryObject(Iads.GetUnit(OU), 1, 2); if (!Iadch.CheckUnit(OU)) { return(2); } try { oDEC.Properties["l"].Value = "9"; result = 1; oDEC.CommitChanges(); } catch { result = 0; errStr = "Err0001"; //未指定错误 } finally { oDEC.Close(); } return(result); }
public void Set_Sign(string cn, out string ErrResult) { try { int i = 0; DirectoryEntry usr = Iadc.GetDirectoryObject(Iads.GetUnit(cn), i); //电话页 usr.Properties["l"].Value = "0"; usr.CommitChanges(); usr.Close(); ErrResult = ""; } catch (Exception ex) { ErrResult = ex.ToString(); } }