.net code to create AD user account
- From: "richb330" <richb999@xxxxxxxxxxx>
- Date: Wed, 13 Jul 2005 13:27:33 +0100
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(strDisplayName)
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?
.
- Follow-Ups:
- Re: .net code to create AD user account
- From: Siva M
- Re: .net code to create AD user account
- Prev by Date: Re: Paste Link or Data into a RichTextBox
- Next by Date: drag-drop file form explorer
- Previous by thread: Serializing and Event-Handlers
- Next by thread: Re: .net code to create AD user account
- Index(es):