Results 1 to 15 of 15

Thread: How to retrieve All info about AD Users ??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    66

    How to retrieve All info about AD Users ??

    Hi,
    i want to get all info about a certain user in the Active Directory,
    i tried to use the following code:
    VB Code:
    1. Set oContainer = GetObject("WinNT://" + "ITAcademy.com")
    2.  
    3.     For Each oIADs In oContainer
    4.         If (oIADs.Class = "User") Then
    5.            Set oUser = oIADs
    When i use this code it can give me small portion of info such as Full Name, but i cant get the mail address, cause i have an error as follows:
    VB Code:
    1. ' The directory property cannpt be found in the cache
    googlin around i found the winNt objects doesn't support such info, so i need to use LDAP code, is there any sample around?

    thanks,

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to retrieve All info about AD Users ??

    Try this.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    66

    Re: How to retrieve All info about AD Users ??

    Well, thank you for the article, but do u know what is the attribute of the email address ie. rs("Mail")???

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by L1nuxVb
    Well, thank you for the article, but do u know what is the attribute of the email address ie. rs("Mail")???
    No, I found that after doing a Google of "ldap vb6"

    Maybe there is other stuff out there that would explain more. I'll see what I can find.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    66

    Re: How to retrieve All info about AD Users ??

    Well , searching around i found something that worked
    VB Code:
    1. Dim conn As New ADODB.Connection
    2. Dim strRS As String
    3. Dim RS As ADODB.Recordset
    4. Dim strconn As String
    5. Private Sub Form_Load()
    6.  
    7. 'Set Conn = Server.CreateObject("ADODB.Connection")
    8. 'Set RS = Server.CreateObject("ADODB.Recordset")
    9. 'Conn.Provider = "ADsDSOObject"
    10. 'strconn = "Active Directory Provider"
    11. conn.Open _
    12.   "Data Source=Active Directory Provider;Provider=ADsDSOObject"
    13.  
    14.  strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
    15.  
    16. Set RS = conn.Execute(strRS)
    17.  While RS.EOF = False
    18. MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
    19. RS.MoveNext
    20. Wend
    21. End Sub

  6. #6
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,933

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by L1nuxVb
    Well , searching around i found something that worked
    VB Code:
    1. Dim conn As New ADODB.Connection
    2. Dim strRS As String
    3. Dim RS As ADODB.Recordset
    4. Dim strconn As String
    5. Private Sub Form_Load()
    6.  
    7. 'Set Conn = Server.CreateObject("ADODB.Connection")
    8. 'Set RS = Server.CreateObject("ADODB.Recordset")
    9. 'Conn.Provider = "ADsDSOObject"
    10. 'strconn = "Active Directory Provider"
    11. conn.Open _
    12.   "Data Source=Active Directory Provider;Provider=ADsDSOObject"
    13.  
    14.  strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
    15.  
    16. Set RS = conn.Execute(strRS)
    17.  While RS.EOF = False
    18. MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
    19. RS.MoveNext
    20. Wend
    21. End Sub
    Hi L1nuxVb tks for share!
    I am a newbie, sure....
    Have idea if existis a list of complete object to retrive other info from LDAP query.?
    You know only Name and Mail?

    Tks from Italy.
    Sal.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by luca90
    Have idea if existis a list of complete object to retrive other info from LDAP query.?
    Like what?

    And, you should start your own thread for this question.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to retrieve All info about AD Users ??

    Hes asking if there is a complete listing of the objects information instead of just the two.

    I supose if you use the "*" in your select query and reference thee field index positions instead of their names you can return and list out all available info.


    Code:
    strRS = "SELECT * FROM 'LDAP://head.com' WHERE objectClass = 'user' "
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,933

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by RobDog888
    Hes asking if there is a complete listing of the objects information instead of just the two.

    I supose if you use the "*" in your select query and reference thee field index positions instead of their names you can return and list out all available info.


    Code:
    strRS = "SELECT * FROM 'LDAP://head.com' WHERE objectClass = 'user' "
    Hi RobDog888 happy to see you on my one post!
    Yes ok for query with "*" ....
    but tell me... wath are the other object disponible:
    computermname, userid...
    have a lists?

  10. #10
    Member
    Join Date
    Mar 2008
    Posts
    38

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by luca90 View Post
    Hi L1nuxVb tks for share!
    I am a newbie, sure....
    Have idea if existis a list of complete object to retrive other info from LDAP query.?
    You know only Name and Mail?

    Tks from Italy.
    Sal.
    Hmmm this seams quite useful, i need to make it only search for a pre-specified login name and then state the name and mail and so on. Anyone know how to?

    br,

    R

  11. #11
    Member
    Join Date
    Mar 2008
    Posts
    38

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by L1nuxVb View Post
    Well , searching around i found something that worked
    VB Code:
    1. Dim conn As New ADODB.Connection
    2. Dim strRS As String
    3. Dim RS As ADODB.Recordset
    4. Dim strconn As String
    5. Private Sub Form_Load()
    6.  
    7. 'Set Conn = Server.CreateObject("ADODB.Connection")
    8. 'Set RS = Server.CreateObject("ADODB.Recordset")
    9. 'Conn.Provider = "ADsDSOObject"
    10. 'strconn = "Active Directory Provider"
    11. conn.Open _
    12.   "Data Source=Active Directory Provider;Provider=ADsDSOObject"
    13.  
    14.  strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
    15.  
    16. Set RS = conn.Execute(strRS)
    17.  While RS.EOF = False
    18. MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
    19. RS.MoveNext
    20. Wend
    21. End Sub
    Something weird happed to the quotation in the above post, well i meant to quote this one anyhow.

    Anyone know how you make this work for grabbing full name and email from a specified login name only. not looping through the whole ad?

    Cheers!

    /Rambit

    EDIT: Clarifying the question
    Last edited by rambit; Jan 17th, 2010 at 03:20 PM.

  12. #12
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by rambit View Post
    Anyone know how you make this work for grabbing full name and email from a specified login name only. not looping through the whole ad?
    Lets pretend the username you need the name and mail for is "IamRambit" in AD.

    Try the below syntax.

    VB Code:
    1. strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' AND sAMAccountName='IamRambit' "

    Let me know if that worked.

    p.s: Make sure you replace IamRambit with the actual <userName> or variable containing the username you need the data for.
    Last edited by Optional; Jan 18th, 2010 at 05:02 AM. Reason: Updated Code Tag to VBCode



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  13. #13
    Member
    Join Date
    Mar 2008
    Posts
    38

    Re: How to retrieve All info about AD Users ??

    Hi optional!

    You seem to be my LDAP savior

    Thanks again, and it did work flawlessly! May i ask if this is a possible method for listing all security groups on a user as well?

    Thanks a milion m8!

    br,

    Rambit

  14. #14
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: How to retrieve All info about AD Users ??

    Quote Originally Posted by rambit View Post
    May i ask if this is a possible method for listing all security groups on a user as well?
    Declare some extra extra variables:
    VB Code:
    1. Dim oUser
    2. Dim group

    Change your Query to:
    VB Code:
    1. strRS = "SELECT name, mail, adsPath FROM 'LDAP://head.com' WHERE objectClass = 'user' AND objectCategory='person' AND sAMAccountName='IamRambit' "

    When you set your RecordSet object you now have also adsPath as a 3rd field returned.
    We are going to use it to extract the groups this user is part of like this:
    VB Code:
    1. Set RS = conn.Execute(strRS)
    2.  
    3. RS.MoveFirst
    4.  
    5. While RS.EOF = False    
    6.     Set oUser = GetObject(RS("adsPath"))
    7.    
    8.     For Each group In oUser.Groups
    9.         MsgBox group.Name
    10.     Next
    11.    
    12.     RS.MoveNext
    13. Wend

    The group names are formatted like this "CN=<groupName>", just trim of the "CN=" part.

    I'm not 100&#37; sure if this is the only way to extract the groups but I hope this will work for you anyway.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  15. #15
    Member
    Join Date
    Mar 2008
    Posts
    38

    Re: How to retrieve All info about AD Users ??

    Thanks alot optional, it worked like a charm!

    best regards,

    Rambit

Posting Permissions

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



Click Here to Expand Forum to Full Width