Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    22

    Unanswered: How to create new User?

    I need code in ASP that create user in the Active Directory Users, in order to open a mail box.

    how can I do it?????

  2. #2
    Join Date
    Sep 2003
    Location
    Newark, Vermont
    Posts
    20
    Need a little more information then that?

  3. #3
    Join Date
    Nov 2003
    Posts
    22

    This is my code

    Originally posted by jlot6
    Need a little more information then that?
    I want to create a new User in my Active Directory

    My code is
    <%

    %

    Dim userName
    Dim userPass
    Dim userAcount


    strName=request.form("text1")
    strInitialPassword= request.form("text2")
    strSAMAccountName= request.form("text3")


    Dim objRootDSE
    Dim objUsers
    Dim objNewUser

    On Error Resume Next

    ' Bind to the rootDSE object.

    Set objRootDSE = GetObject("LDAP://rootDSE")
    If (Err.Number <> 0) Then
    response.write "Error1 "
    End If

    ' Bind to the Users folder in the domain.
    Set objUsers = GetObject("LDAP://CN=Users," & objRootDSE.Get("defaultNamingContext"))
    If (Err.Number <> 0) Then
    response.write "Error2 "
    End If

    ' Create the user object.
    Set objNewUser = objUsers.Create("user", "CN=" + strName)
    If (Err.Number <> 0) Then
    response.write "Error3 "
    End If

    ' Set the sAMAccountName property.
    objNewUser.Put "sAMAccountName", strSAMAccountName

    If (Err.Number <> 0) Then
    response.write "Error4 "
    End If

    ' Commit the new user.
    objNewUser.SetInfo
    If (Err.Number <> 0) Then
    response.write "Error5 "
    End If

    ' Set the initial password. This must be done after
    ' SetInfo is called because the user object must
    ' already exist on the server.
    objNewUser.SetPassword strInitialPassword
    If (Err.Number <> 0) Then
    response.write "Error6 "
    End If

    ' Set the pwdLastSet property to zero, which forces the
    ' user to change the password at next log on.
    objNewUser.Put "pwdLastSet", 0
    If (Err.Number <> 0) Then
    response.write "Error7 "
    End If


    userActCtrl = objNewUser.Get("userAccountControl")
    userActCtrl = userActCtrl And Not (ADS_UF_ACCOUNTDISABLE + ADS_UF_PASSWD_NOTREQD + ADS_UF_DONT_EXPIRE_PASSWD)
    objNewUser.Put "userAccountControl", userActCtrl
    If (Err.Number <> 0) Then
    response.write "Error8 "
    End If

    objNewUser.SetInfo


    %>


    It's print to me "Error5" What's wrong??? Untill "Error5" no problems.
    How to fix it???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •