Hello all, I new to active directory.. i have the following code to
create a new user and assign a group to that user... which create a
user in Local User and group section of Administrative tools/computer
managment .
// create user
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add(textUserName.Text, "user");
NewUser.Invoke("SetPassword", new object[] {textPassword.Text});
NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
NewUser.CommitChanges();
// assign group
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null)
{grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
MessageBox.Show("Account created successfully");
Here
is a code to authentcate user... but it gives a error like..."The
provider does not support searching and cannot search
WinNT://ADMIN,computer." I also confuse when to use "LDAP" protocol and
when "WinNT".
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
Object obj = AD.NativeObject;
DirectorySearcher directorySearcher = new DirectorySearcher(AD);
directorySearcher.Filter ="(SAMAccountName = " + textUserName.Text + ")";
directorySearcher.PropertiesToLoad.Add("cn");
SearchResult sr = directorySearcher.FindOne();
if (sr == null)
{
MessageBox.Show("Not Authenticated!!");
}
else
{
MessageBox.Show("Authenticated!!");
}
If anybody has a idea.. plz HELP...
Loading

kalyan BandarupalliPosted Jan 2, 2008, 7:40 AM
Hi
WinNT, LDAP both are protocols to connect to the active directory in the servers.
In order to create a new user in activedirectory you must have administrative previlages then only user will be created. you need to set the following properties to directory entry object
de.UserName // Administrator or the person who is Admin group
de.Password // Corresponding pwd
de.Path // Active Directory Path (LDAP)
de.AuthenticationType //Secure