Error creating a user in active directory

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

RJLemonAsked:
Who is Participating?
 
Dustin HopkinsConnect With a Mentor Managing MemberCommented:
try changing your add statement to this
deNew_User = deUsers_In_OU.Add("CN=" & strSAM_ACCT, "user")

0
 
Dustin HopkinsManaging MemberCommented:
Also here is a really good site for common active directory operations, using .net/c#.
0
 
RJLemonAuthor Commented:
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
 
Dustin HopkinsManaging MemberCommented:
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
 
RJLemonAuthor Commented:
So simple a solution for such a hard problem.

Greatly appreciated.
0
All Courses

From novice to tech pro — start learning today.