private void AddUser(string strDoamin, string strLogin, string strPwd)
{
DirectoryEntry obDirEntry = null;
try
{
obDirEntry = new DirectoryEntry("WinNT://" + strDoamin);
DirectoryEntries entries = obDirEntry.Children;
DirectoryEntry obUser = entries.Add(strLogin, "User");
obUser.Properties["FullName"].Add("Amigo");
object obRet = obUser.Invoke("SetPassword", strPwd);
obUser.CommitChanges();
}
catch (Exception ex)
{
}
}
在XP和2000中添加一个用户
最新推荐文章于 2022-08-31 17:16:04 发布
博客展示了一段C#代码,定义了一个名为AddUser的私有方法,用于在指定域中添加用户。方法接收域名、登录名和密码作为参数,通过DirectoryEntry对象操作,尝试添加用户并设置密码,同时捕获可能出现的异常。
2384

被折叠的 条评论
为什么被折叠?



