首页 > 代码库 > HOW DO YOU DO: CREATE AD USER AND ADD THIS INTO GROUP
HOW DO YOU DO: CREATE AD USER AND ADD THIS INTO GROUP
Liunx:
static void Main(string[] args)
{
try
{
string[] groups = new string[] { "Admin", "Back_End", "CSharp", "Developer", "Faserati", "Flex", "Front-End", "HTML", "JS", "SQL", "Teacher", "Tester" };
DirectoryEntry root = new DirectoryEntry();
root.Path = "LDAP://FAST.Faserati/CN=Users,DC=FAST,DC=Faserati";
root.Username = "Administrator";
root.Password = "P@$$w0rd";
DirectoryEntry group = new DirectoryEntry();
group.Path = "LDAP://FAST.Faserati";
group.Username = "Administrator";
group.Password = "P@$$w0rd";
group.Children.SchemaFilter.Add("group");
for (int i = 0; i < 10000; i++)
{
Random r = new Random();
string g = groups[r.Next(0, 11)];
DirectoryEntry parent = group.Children.Find("CN=" + g);
parent.Invoke("Add", CreateUser(root, g + i.ToString()).Path.ToString());
}
}
catch (COMException ex)
{
Console.WriteLine(ex.Message);
}
}
static DirectoryEntry CreateUser(DirectoryEntry root, string userName)
{
using (var de = new DirectoryEntry())
{
de.Path = "LDAP://FAST.Faserati/CN=Users,DC=FAST,DC=Faserati";
de.Username = "Administrator";
de.Password = "P@$$w0rd";
DirectoryEntry user = root.Children.Add("CN=" + userName, "user");
user.Properties["company"].Add("Faserati");
user.Properties["employeeID"].Add("4711");
user.Properties["samAccountName"].Add(userName);
user.Properties["userPrincipalName"].Add(userName + "@explorer.local");
user.Properties["sn"].Add("Doe");
user.Properties["mail"].Add(userName + "@Faserati.com");
user.Properties["userPassword"].Add("someSecret");
user.Properties["userAccountControl"].Add(544);
user.CommitChanges();
return user;
}
Windows:
http://technet.microsoft.com/en-us/library/cc783256(v=ws.10).aspx
http://wenku.baidu.com/link?url=LewnAPwN0b7KLzTqm6L6yUWIL4s8ulFAZS4beoBoAAEtQ0AkFNZJC0p27n9ynArElwXlDOqq86VvkPyJMapTiAk8yjg8_BvcXWIkcL9apkm
HOW DO YOU DO: CREATE AD USER AND ADD THIS INTO GROUP