casmir.dominic 0 Newbie Poster

Is it possible to add a user in a specific domain through coding in asp.net.My code behind is vb.Please give me syntax.
As of now, i ll give u a reference coding

Sub AddUser(ByVal folderPath, ByVal userName)
        'creating a account in the active directory so that the particular account can alone access 
        'the file
        Dim AD As New DirectoryServices.DirectoryEntry
        AD = New DirectoryServices.DirectoryEntry("WinNT://" + Environment.MachineName + ",computer")
        Dim objUser As System.DirectoryServices.DirectoryEntry = Nothing
        Try
            'checking whether the account is already present in the active directory
            objUser = AD.Children.Find(userName, "user")
        Catch
        End Try
        If objUser Is Nothing Then
            'if there is no acccount,we are creating a user
            objUser = AD.Children.Add(userName, "user")
            'objUser.Invoke("SetPassword", New Object() {Session("password101")})
            objUser.Invoke("SetPassword", New Object() {"#12345Abc"})
            objUser.CommitChanges()
            objUser.Invoke("Put", New Object() {"Description", "Created by Casmir for Demo Project "})
            objUser.CommitChanges()
            Dim grp As DirectoryServices.DirectoryEntry
            'grp = AD.Children.Find("Users", "group")
            grp = AD.Children.Find("Administrators", "group")
            If grp IsNot "" Then
                grp.Invoke("Add", New Object() {objUser.Path.ToString()})
            End If

            objUser.CommitChanges()
            objUser.RefreshCache()
            MessageBox("new account is successfully created ")
        Else
            MessageBox("account already exists in active directory ")
        End If
            End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.