problems creating a user in Active directory

Discussion in 'ASP .Net' started by Carlettus, Jun 12, 2007.

  1. Carlettus

    Carlettus Guest

    Dear All,
    sorry but I'm not sure if this is the right place to post my problem.
    I was using the following asp code to create users in Active Directory.
    Suddenly, and I don't know the reason, users are created but the account is
    disabled (see the flag User.AccountDisabled = False ).
    There is also another problem even if the user does not exist , the
    application returns to me with the message that the user already exist.

    Thank you for your support
    Carlo




    ---------------------------------------------------

    <%

    On Error Resume Next
    '/// Variable Declarations

    Dim User, Container, TargetContainer, sObjectCommonName, FirstName, LastName
    Dim ObjectSAMName, InitialPassword, sUserPrincipalName, sUserPath, sFullName
    Dim szUsername, szPassword, sOU, intUAC

    Const ADS_SECURE_AUTHENTICATION = 1
    Const ADS_UF_ACCOUNTDISABLE = 2

    Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

    sOU = Request.Form("name_ou")

    '/// Assign variable values from the form

    TargetContainer = "LDAP://OU=" & sOU &
    ",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"
    szUsername = (Request.ServerVariables("AUTH_USER"))
    szPassword = Request.Form("password")
    ObjectSAMName = Request.Form("acc_logname")
    InitialPassword = Request.Form("acc_passwd")
    FirstName = Request.Form("acc_firstname")
    LastName = Request.Form("acc_lastname")
    sObjectCommonName = LastName & "\, " & FirstName
    sFullName = FirstName & " " & LastName
    sUserPath = "LDAP://CN=" & sObjectCommonName & ",OU=" & sOU &
    ",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"

    Set obj1 = GetObject(TargetContainer)

    '/// check if a user already exists

    Dim strUserName
    CheckForUser(ObjectSAMName)
    Sub CheckForUser(samAccountName)
    strUserName = samAccountName

    '/// Create, configure, and open ADO Connection object

    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"

    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection

    objCommand.CommandText = _
    "<LDAP://OU=" & sOU &
    ",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG>;(&(objectCategory=User)" & _
    "(samAccountName=" & strUserName & "));samAccountName;subtree"


    Set objRecordSet = objCommand.Execute

    If objRecordset.RecordCount = 0 Then


    '/// If the user does not exist, then create the account and
    '/// populates the object's properties

    Set User = obj1.Create("user", "CN=" & sObjectCommonName)
    User.Put "sAMAccountName", ObjectSAMName
    User.Put "givenName", FirstName
    User.Put "sn", LastName
    User.Put "userPrincipalName", ObjectSAMName
    User.Put "DisplayName", LastName & " " & FirstName
    User.Put "Description", "Sharepoint use only: created by " & szUsername
    User.SetInfo

    '/// Sets the password and enables the account

    intUAC = User.Get("userAccountControl")
    User.Put "userAccountControl", ADS_UF_DONT_EXPIRE_PASSWD
    User.SetInfo

    User.SetPassword InitialPassword
    User.AccountDisabled = False
    User.SetInfo

    If Err.Number = 0 Then

    '/// If no errors occur, it displays a success screen

    Response.redirect "result.asp"
    Else

    '/// If an error occurs, it displays an error message

    Response.redirect "result_no.asp"
    End If

    Else
    End If

    '/// Clean up

    objConnection.Close

    End Sub
    %>
    Carlettus, Jun 12, 2007
    #1
    1. Advertising

  2. Ysgrifennodd Carlettus:
    > Dear All,
    > sorry but I'm not sure if this is the right place to post my problem.
    > I was using the following asp code to create users in Active Directory.
    > Suddenly, and I don't know the reason, users are created but the account is
    > disabled (see the flag User.AccountDisabled = False ).
    > There is also another problem even if the user does not exist , the
    > application returns to me with the message that the user already exist.
    >
    > Thank you for your support
    > Carlo
    >


    There's microsoft.public.adsi.general newsgroup that you might like to
    try. This book (by a regular contributor to the newsgroup) is also
    excellent - but only if you're using .NET.

    HTH


    Peter
    Peter Bradley, Jun 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J'son
    Replies:
    0
    Views:
    356
    J'son
    Apr 22, 2005
  2. J'son
    Replies:
    5
    Views:
    2,679
    J'son
    Apr 26, 2005
  3. ejcosta
    Replies:
    2
    Views:
    868
    Eurico Costa
    Oct 8, 2004
  4. J'son
    Replies:
    5
    Views:
    154
    J'son
    Apr 26, 2005
  5. A. Farber
    Replies:
    1
    Views:
    615
    A. Farber
    Mar 13, 2009
Loading...

Share This Page