Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB to talk to ADSI - Write to Users

Status
Not open for further replies.

txgeekgirl1

Programmer
Sep 10, 2009
85
0
0
US
I have this bit of code and need to write to the Users folder in Active Directory. How would I add that Folder to the dirEntry var?

Code:
 Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
     

        CreateAdAccount(UserName.Text, "", "", "", "")
        
    End Sub
    Public Sub CreateAdAccount(ByVal sUserName As String, _
       ByVal sPassword As String, _
       ByVal sFirstName As String, ByVal sLastName As String, _
       ByVal sGroupName As String)

        Dim catalog As Catalog = New Catalog()
        Dim dirEntry As New DirectoryEntry()

        ' 1. Create user account
        Dim adUsers As DirectoryEntries = dirEntry.Children

        Dim newUser As DirectoryEntry = adUsers.Add("CN=" & sUserName, "User")

        ' 2. Set properties
        SetProperty(newUser, "givenname", sFirstName)
        SetProperty(newUser, "sn", sLastName)
        SetProperty(newUser, "SAMAccountName", sUserName)
        SetProperty(newUser, "userPrincipalName", sUserName)
        newUser.CommitChanges()
        ' 3. Set the password
        SetPassword(newUser, sPassword)
        ' 5. Add the user to the specified group
        AddUserToGroup(dirEntry, newUser, sGroupName)
        ' 6. Enable the account
        EnableAccount(newUser)
        ' 7. Close & clean-up
        newUser.Close()
        dirEntry.Close()
    End Sub
 
something along the lines of...

Code:
objUser.Put "homeDirectory", "\\Server\HomeDir\SAMAccountName"
objUser.Put "homeDrive", "H:"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top