Hi,
I have code from the msdn to crate a user in an AD domain. I have set the
code and changed the necessary parameters for the ldap queries but was
wondering how i can execute this code on a button press. I can't put this
code within the button private sub of the button as i receive errors within
the code.
What do i need to do to start this off from the executed button?
The code is as follows..
lass CreateUser
'/ <summary>
'/ Create ADAM User.
'/ </summary>
<STAThread()> Shared Sub Main()
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.
' Construct the binding string.
strPath = "LDAP://localhost:389/O=Fabrikam,C=US"
Console.WriteLine("Bind to: {0}", strPath)
' Get ADAM object.
Try
objADAM = New DirectoryEntry(strPath)
objADAM.RefreshCache()
Catch e As Exception
Console.WriteLine("Error: Bind failed.")
Console.WriteLine(" {0}", e.Message)
Return
End Try
' Specify User.
strUser = "CN=TestUser"
strDisplayName = "Test User"
strUserPrincipalName = "Te******@Fabrikam.Us"
Console.WriteLine("Create: {0}", strUser)
' Create User.
Try
objUser = objADAM.Children.Add(strUser, "user")
objUser.Properties("displayName").Add(strDisplayNa me)
objUser.Properties("userPrincipalName").Add( _
strUserPrincipalName)
objUser.CommitChanges()
Catch e As Exception
Console.WriteLine("Error: Create failed.")
Console.WriteLine(" {0}", e.Message)
Return
End Try
' Output User attributes.
Console.WriteLine("Success: Create succeeded.")
Console.WriteLine("Name: {0}", objUser.Name)
Console.WriteLine(" {0}", _
objUser.Properties("displayName").Value)
Console.WriteLine(" {0}", _
objUser.Properties("userPrincipalName").Value)
Return
End Sub 'Main
End Class 'CreateUser
thanks