Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • 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 HopkinsCommented:
try changing your add statement to this
deNew_User = deUsers_In_OU.Add("CN=" & strSAM_ACCT, "user")

0
 
Dustin HopkinsCommented:
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 HopkinsCommented:
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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