比如:我建立一个ls组,想要通过程序把用户xiaoming添加到组ls中。请问应当怎么处理?
解决方案 »
- 帮忙看下这代码肿么回事?3Q~
- listview中如何只能右键有数据的行
- 想出来的问题,大侠们帮忙解决下
- 水晶报表问题:该报表不包含表。(问题程序:★★★★★)
- 新手问题:关于窗体子控件的事件传递问题
- 用C#如何捕捉打印信息呀?
- 开发和技术支持哪个更有前途?
- 微软专家,映射网络驱动器与操作系统版本有关系??(windwos XP成功,同样代码在2003就不行)
- 使用了classA:classB,System.Security.Principal.IIdentity报错!
- 怎么添加PlotView控件?
- 请问浪人算牌 和 必胜客算牌器 这些软件的实现原理
- [求助] 求一个c/s模式并采用异步Socket的 某管理系统代码
DirectoryEntry newEntry;
string entryName="cn=testuser";
newEntry=entry.Children.Add(entryName,"user");
newEntry.UsePropertyCache=true;
newEntry.Properties["sAMAccountName"].Value="userID";
newEntry.Properties["userPrincipalName"].Value="userID";
newEntry.CommitChanges();http://topic.csdn.net/t/20030428/22/1719106.html
{
DirectoryEntry oGroup = SearchGroupPath(GroupName);
DirectoryEntry oUser = SearchUserPath(UserName);
//Add the user to the group via the invoke method
oGroup.Invoke("Add", new Object[] { oUser.Path.ToString() }); oGroup.CommitChanges(); oGroup.Close();
oUser.Close();
}
什么意思?? public static DirectoryEntry SearchGroupPath(string GroupName)
{
DirectoryEntry de = GetDirectoryObject();
try
{
//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher(); //set the search filter
deSearch.SearchRoot = de;
//deSearch.PropertiesToLoad.Add("cn");
deSearch.Filter = "(&(objectClass=group)(cn=" + GroupName + "))"; //get the group result
SearchResult results = deSearch.FindOne(); //if the group is valid, then continue, otherwise return a blank dataset
if (results != null)
{
//create a link to the group object, so we can get the list of members
//within the group return results.GetDirectoryEntry();
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public static DirectoryEntry SearchUserPath(string UserName)
{
//create an instance of the DirectoryEntry
DirectoryEntry de = GetDirectoryObject();
//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher(); deSearch.SearchRoot = de;
//set the search filter
deSearch.Filter = "(&(objectClass=user)(cn=" + UserName + "))";
deSearch.SearchScope = SearchScope.Subtree;
try
{
//find the first instance
SearchResult results = deSearch.FindOne(); de = new DirectoryEntry(results.Path, _ADUser, _ADPassWord, AuthenticationTypes.Secure);
//if so then return the DirectoryEntry object
return de;
}
catch
{
return null;
}
}