Active Driectory question 
Author Message
 Active Driectory question

Hi all,

How do I add an active directory user using C#?

Here is the code I am using:

DirectoryEntry de = new DirectoryEntry();

de.Path = "LDAP://1.1.1.1/CN=Users, DC=xxx, DC=com";

DirectoryEntries users = de.Children;

DirectoryEntry newUser = users.Add(pName, "user");

newUser.Properties["cn"].Add("Test User");

newUser.Properties["samAccountName"].Add("TestU");

newUser.Properties["userPassword"].Add("password");

newUser.CommitChanges();

And here is the error message that I receive:

Error: The server is unwilling to process the request.

What am I missing? Are there mandatory attributes that I need to set?

Thanks,
  Mark.



Sun, 31 Oct 2004 19:26:20 GMT  
 Active Driectory question
Mark, there are a couple of things that you should try.

1. Does the user you are running under have permission to write to the
Active Directory Users container?
2. Try commenting out your add password line and use SetPassword or the
password attribute on the DirectoryEntry object.
3. If that fails load up your AD schema and make sure you are setting all of
the mandatory attributes.

(Search for ADSI Edit on MSDN or google if you need a tool to do #1 or #3)

--
Greg
http://www.claritycon.com/


Quote:
> Hi all,

> How do I add an active directory user using C#?

> Here is the code I am using:

> DirectoryEntry de = new DirectoryEntry();

> de.Path = "LDAP://1.1.1.1/CN=Users, DC=xxx, DC=com";

> DirectoryEntries users = de.Children;

> DirectoryEntry newUser = users.Add(pName, "user");

> newUser.Properties["cn"].Add("Test User");

> newUser.Properties["samAccountName"].Add("TestU");

> newUser.Properties["userPassword"].Add("password");

> newUser.CommitChanges();

> And here is the error message that I receive:

> Error: The server is unwilling to process the request.

> What am I missing? Are there mandatory attributes that I need to set?

> Thanks,
>   Mark.



Sun, 31 Oct 2004 21:17:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ELECTRONICS DRIECTORY

2. Obtaining active view and active doc from theApp object

3. Have non-active MDI child maximized while active is not maximized

4. Active Directory, DirectorySearcher and Filter question

5. Active Directory Question

6. Active Scripting questions

7. debugging Active X DLLs: kinda advanced question

8. Active X - beginner question

9. Dumb Question...Diff between Active X and OCX

10. Active Question?

11. Add-In für Visual Studio / Active X (Newbie questions)

12. Active X Control Question

 

 
Powered by phpBB® Forum Software