• Querying Active Directory (Win 2k, Office 2k)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Querying Active Directory (Win 2k, Office 2k)

    Author
    Topic
    #386052

    Hi folks

    I found this section of script useful.. sourced from FreeVBCode.com
    My question is this ..
    How can I return information from AD based on input which is user intials ? Assume that a unique combo of initals is used .
    ‘==============================
    Set oRoot = GetObject(“LDAP://rootDSE”)
    ‘work in the default domain
    sDomain = oRoot.Get(“defaultNamingContext”)
    Set oDomain = GetObject(“LDAP://” & sDomain)
    sBase = “”
    ‘Only get user name requested
    sFilter = “(&(objectCategory=person)(objectClass=user)(name=” _
    & LoginName & “))”
    ‘ ———————————
    ‘can we modify the line above for user initials
    ‘———————————

    sAttribs = “adsPath”
    sDepth = “subTree”

    sQuery = sBase & “;” & sFilter & “;” & sAttribs & “;” & sDepth

    conn.Open _
    “Data Source=Active Directory Provider;Provider=ADsDSOObject”

    Set rs = conn.Execute(sQuery
    ‘===========================

    Thanks in advance

    Geof

    Viewing 0 reply threads
    Author
    Replies
    • #668391

      Hi Geof,
      As far as I know AD does not store user initials as an attribute type, so you would either need a translation table so that you can input user initials but actually look up user names, or you would need to parse the initials and do a search using something like:

      sFilter = "(&(objectCategory=person)(objectClass=user) _
      (&(name="& strInitial1 & "*)(sn="&strInitial2&"*))"

      assuming 2 initials in a unique combination.
      (Note: that’s air code so I can’t guarantee it’s correct syntax!)
      HTH.

      • #668563

        Thanks for the help Rory
        Will let you know how I get on

        Cheers
        Geof

      • #668728

        “Air Code”
        I like that term. For compilation in the mind only. Output results will vary.

    Viewing 0 reply threads
    Reply To: Querying Active Directory (Win 2k, Office 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: