Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 895
  • Last Modified:

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

0
RJLemon
Asked:
RJLemon
  • 3
  • 2
1 Solution
 
Dustin HopkinsSenior Web DeveloperCommented:
try changing your add statement to this
deNew_User = deUsers_In_OU.Add("CN=" & strSAM_ACCT, "user")

0
 
Dustin HopkinsSenior Web DeveloperCommented:
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 HopkinsSenior Web DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now