Solved

Error creating a user in active directory

Posted on 2008-06-24
5
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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