system.directoryservices add user failure

C

Cameron Frasnelly

Can anyone tell me why the below keeps giving me
[COMException (0x80072035): The server is unwilling to process the request.]

If Impersonation_MOD.impersonateValidUser("DomainAdmin", "pwst.intra",
"Password") = True Then

Dim AD As DirectoryEntry = New DirectoryEntry("LDAP://pwst.intra",
"DoaminAdmin", "Password")

Dim NewUser As DirectoryEntry = AD.Children.Add("CN=Testerboy", "user")

NewUser.Properties("samAccountName").Add("Tester1.Tester2")

NewUser.Properties("givenName").Add("Tester1")

NewUser.Properties("sn").Add("Tester2")

NewUser.Properties("userAccountControl").Add(512)

NewUser.CommitChanges()

NewUser.Invoke("SetPassword", "Minetoday1")

NewUser.CommitChanges()

Impersonation_MOD.undoImpersonation()

End If
 
T

Tom Wu

Dear Cameron,

Thanks for your posting.

It appears that this is a Development related request and would best be
address in the Developer newsgroups. I have provided the link below:

http://msdn.microsoft.com/newsgroups/default.asp

Regards,

Tom Wu, MCSE 2000
Microsoft Partner Online Support
Get Secure! - www.microsoft.com/security

====================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Matjaz Ladava [MVP]

I did this in C# and it works. What you are doing wrong is that you are not doing this in a container or in a OU. Just change your initial LDAP bind.

DirectoryEntry ad = new DirectoryEntry(LDAP://cn=Users,dc=domain,dc=com,"AdminUser", "password");
DirectoryEntry newUser = ad.Children.Add("CN=Testerboy", "user");
newUser.Properties["samAccountName"].Add("Tester1.Tester2");
newUser.Properties["givenName"].Add("Tester1");
newUser.Properties["sn"].Add("Tester2");
newUser.Properties["userAccountControl"].Add(512);
newUser.CommitChanges();
newUser.Invoke("SetPassword", "Minetoday1");
newUser.CommitChanges();

I don't use VB anymore (since .NET era), but I think that this C# code should be easy to understand.

--
Regards

Matjaz Ladava, MCSE (NT4 & 2000), MVP
(e-mail address removed)
http://ladava.com

Cameron Frasnelly said:
The first NewUser.CommitChanges() gives me the error... yes I tried it
without the impersonation... thanks for your time!!!

Matjaz Ladava said:
Which line gives you the error ? Have you tried this w/o using impersonation
with Domain Admin account ?

--
Regards

Matjaz Ladava, MCSE (NT4 & 2000), MVP
(e-mail address removed)
http://ladava.com

Cameron Frasnelly said:
Can anyone tell me why the below keeps giving me
[COMException (0x80072035): The server is unwilling to process the request.]

If Impersonation_MOD.impersonateValidUser("DomainAdmin", "pwst.intra",
"Password") = True Then

Dim AD As DirectoryEntry = New DirectoryEntry("LDAP://pwst.intra",
"DoaminAdmin", "Password")

Dim NewUser As DirectoryEntry = AD.Children.Add("CN=Testerboy", "user")

NewUser.Properties("samAccountName").Add("Tester1.Tester2")

NewUser.Properties("givenName").Add("Tester1")

NewUser.Properties("sn").Add("Tester2")

NewUser.Properties("userAccountControl").Add(512)

NewUser.CommitChanges()

NewUser.Invoke("SetPassword", "Minetoday1")

NewUser.CommitChanges()

Impersonation_MOD.undoImpersonation()

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top