Solved

Error creating a user in active directory

Posted on 2008-06-24
5
857 Views
Last Modified: 2013-11-26
I am trying to create a user in vb.net 2005 via the system.directoryservices calls and I get an error that I am not able to figure out.

I am logged in as the domain administrator and am able to change properties on existing users.  I have included the function I have created that is giving me the error.

The Error is:

An invalid dn syntax has been specified. (Exception from HRESULT: 0x80072032)
Public Function Create_User(ByVal deOU_To_Hold_User As System.DirectoryServices.DirectoryEntry, ByVal strSAM_ACCT As String) As System.DirectoryServices.DirectoryEntry
		Dim deNew_User As DirectoryServices.DirectoryEntry
 
		Dim deUsers_In_OU As DirectoryServices.DirectoryEntries
 
		Try
			deUsers_In_OU = deOU_To_Hold_User.Children
 
			deNew_User = deUsers_In_OU.Add(strSAM_ACCT, "User")
			deNew_User.Properties("SAMAccountName").Add(strSAM_ACCT)
			deNew_User.CommitChanges()
 
			Create_User = deNew_User
		Catch ex As Exception
			mstrErrorText = ex.Message
 
			Create_User = Nothing
		End Try
	End Function

Open in new window

0
Comment
Question by:RJLemon
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 21859410
try changing your add statement to this
deNew_User = deUsers_In_OU.Add("CN=" & strSAM_ACCT, "user")

0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21859441
Also here is a really good site for common active directory operations, using .net/c#.
0
 

Author Comment

by:RJLemon
ID: 21859528
Hi Dusion,

Did you mean to provide a link or URL.  I don't see it.

I will try your suggestions in a few minutes.

Thanks.
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21859564
Oops: I guess I'm trying to do too many things at once.
here is the link
http://www.dotnettreats.com/tipstricks/adnet.aspx#s10
0
 

Author Closing Comment

by:RJLemon
ID: 31470230
So simple a solution for such a hard problem.

Greatly appreciated.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question