Forums

Welcome to Forums Sign in | Join | Help
in Search

Creating users in Active Directory (ActiveX sample)

Last post 03-11-2007, 11:57 PM by Michal. 0 replies.
Sort Posts: Previous Next
  •  03-11-2007, 11:57 PM 1996

    Creating users in Active Directory (ActiveX sample)

    Some sample code for creating users and setting passwords in AD:

    servername = ...
    adminusername = ...
    adminpassword = ...
    baseUsersDn = "cn=Users,dc=...,dc=..."

    ' Create the user
    Set ldap = CreateObject("LDAPClient.3")
    Call ldap.Connect(servername, , adminusername, adminpassword)

    Set attributes = CreateObject("LDAPClient.StringDictionary")

    Call attributes("objectClass").Add("top")
    Call attributes("objectClass").Add("person")
    Call attributes("objectClass").Add("organizationalPerson")
    Call attributes("objectClass").Add("user")
    Call attributes("cn").Add("Glenn Livet")
    Call attributes("sn").Add("Livet")
    Call attributes("givenName").Add("Glenn")
    Call attributes("sAMAccountName").Add("glivet")
    Call attributes("userAccountControl").Add("66048") ' Enable the account
    Call attributes("userPassword").Add("dummy") ' do this to satisfy policy

    Call ldap.AddNewEntry("cn=Glenn Livet," + baseUsersDn, attributes)

    ' Use ADSI to set the password
    Set user = GetObject("LDAP://" + "cn=Glenn Livet," + baseUsersDn)
    Call user.SetPassword("newpassword")

View as RSS news feed in XML