473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.net code to create AD user account

I'm trying to set up a program that will create a user account within active
directory based on a number of parameters selected on a form.

The following code should, i believe, create a user account within the AD.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim objADAM As DirectoryEntry ' Binding object.

Dim objUser As DirectoryEntry ' User object.

Dim strDisplayName As String ' Display name of user.

Dim strPath As String ' Binding path.

Dim strUser As String ' User to create.

Dim strUserPrincipalName As String ' Principal name of user.

Dim strPassword As String ' Password

' Construct the binding string.

strPath = LDAP://OU=temp,DC=domainname,DC=com

' Set ADAM object.

strUser = "George Michael"

strDisplayName = "George Michael"

strUserPrincipalName = "gmich1"

strPassword = "summer"

objADAM = New DirectoryEntry(strPath)

objADAM.RefreshCache()
' Create User.

objUser = objADAM.Children.Add(strUser, "user")

objUser.Properties("displayName").Add(strDisplayNa me)

objUser.Properties("userPrincipalName").Add( _

strUserPrincipalName)

objUser.Invoke("SetPassword", strPassword)

objUser.CommitChanges()

MsgBox("done")

End Sub
But when I run it in debug mode the code gets to
objUser.Invoke("SetPassword", strPassword)

and stops with:-

'an unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.'

has anybody got any ideas?


Nov 21 '05 #1
1 4405
Can you try setting the password after calling CommitChanges()?

Also, make sure the password you set conforms to password complexity rules
set at the domain level.

-Siva

"richb330" <ri******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I'm trying to set up a program that will create a user account within active
directory based on a number of parameters selected on a form.

The following code should, i believe, create a user account within the AD.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim objADAM As DirectoryEntry ' Binding object.

Dim objUser As DirectoryEntry ' User object.

Dim strDisplayName As String ' Display name of user.

Dim strPath As String ' Binding path.

Dim strUser As String ' User to create.

Dim strUserPrincipalName As String ' Principal name of user.

Dim strPassword As String ' Password

' Construct the binding string.

strPath = LDAP://OU=temp,DC=domainname,DC=com

' Set ADAM object.

strUser = "George Michael"

strDisplayName = "George Michael"

strUserPrincipalName = "gmich1"

strPassword = "summer"

objADAM = New DirectoryEntry(strPath)

objADAM.RefreshCache()
' Create User.

objUser = objADAM.Children.Add(strUser, "user")

objUser.Properties("displayName").Add(strDisplayNa me)

objUser.Properties("userPrincipalName").Add( _

strUserPrincipalName)

objUser.Invoke("SetPassword", strPassword)

objUser.CommitChanges()

MsgBox("done")

End Sub
But when I run it in debug mode the code gets to
objUser.Invoke("SetPassword", strPassword)

and stops with:-

'an unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.'

has anybody got any ideas?

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1352
by: ziggs | last post by:
I have an Access 97 DB called employees.mdb within a NT security type folder. Other users have write privileges to this document to make updates. This Access DB is only used for an ASP called...
0
2795
by: Ola Ogunneye | last post by:
--=_075912CF.F899D547 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hello again all, I have created an account in the particular database that I was trying to...
2
1500
by: Jim G | last post by:
I have two tables: TestA and TestB. Both tables have 3 fields: ID, Name, and RunDate. I need to create a query which will join the two tables first on Name but then I need to match up the...
2
3091
by: Keith Jakobs, MCP | last post by:
Greetings: I had seen several posts around the Internet about this issue from a few months back, but have been unable to find a resolution ... I have a user who is trying to get started with...
4
3583
by: cmc | last post by:
Hi, I 'm new to DB2 (from Oracle background) and have some fundamental question. In Oracle, you create user account "within the database" to let user to logon to the database. There is no tie...
8
1605
by: Mike | last post by:
is there a tool that will convert cold fusion code to C#? Or anything out there to help in this process? thx
5
1254
by: Rudy | last post by:
Hello All! Can you dynamicly create a folder in ASP.net? Here is the set up. I have a folder where I will store pics. What I would like to do is create a cookie, track the user who has logged...
10
4925
by: robwharram | last post by:
Hi, I'm quite frustrated in the fact that I can't even display a simple "Hello World" message on .Net. I've been through all of the groups and searched all over the place and haven't been able...
4
3466
by: Dan Holmes | last post by:
I admit this not being C# specific but i don't know where else to start. My application needs an "administrator" user id. This would function just like the "administrator" user id in windows. ...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.