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:
Set oContainer = GetObject("WinNT://" + "ITAcademy.com")
For Each oIADs In oContainer
If (oIADs.Class = "User") Then
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:
' 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,
Re: How to retrieve All info about AD Users ??
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")???
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.
Re: How to retrieve All info about AD Users ??
Well , searching around i found something that worked
VB Code:
Dim conn As New ADODB.Connection
Dim strRS As String
Dim RS As ADODB.Recordset
Dim strconn As String
Private Sub Form_Load()
'Set Conn = Server.CreateObject("ADODB.Connection")
'Set RS = Server.CreateObject("ADODB.Recordset")
'Conn.Provider = "ADsDSOObject"
'strconn = "Active Directory Provider"
conn.Open _
"Data Source=Active Directory Provider;Provider=ADsDSOObject"
strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
Set RS = conn.Execute(strRS)
While RS.EOF = False
MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
RS.MoveNext
Wend
End Sub
Re: How to retrieve All info about AD Users ??
Quote:
Originally Posted by L1nuxVb
Well , searching around i found something that worked
VB Code:
Dim conn As New ADODB.Connection
Dim strRS As String
Dim RS As ADODB.Recordset
Dim strconn As String
Private Sub Form_Load()
'Set Conn = Server.CreateObject("ADODB.Connection")
'Set RS = Server.CreateObject("ADODB.Recordset")
'Conn.Provider = "ADsDSOObject"
'strconn = "Active Directory Provider"
conn.Open _
"Data Source=Active Directory Provider;Provider=ADsDSOObject"
strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
Set RS = conn.Execute(strRS)
While RS.EOF = False
MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
RS.MoveNext
Wend
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.
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. :)
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' "
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?
Re: How to retrieve All info about AD Users ??
Quote:
Originally Posted by
luca90
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
Re: How to retrieve All info about AD Users ??
Quote:
Originally Posted by
L1nuxVb
Well , searching around i found something that worked
VB Code:
Dim conn As New ADODB.Connection
Dim strRS As String
Dim RS As ADODB.Recordset
Dim strconn As String
Private Sub Form_Load()
'Set Conn = Server.CreateObject("ADODB.Connection")
'Set RS = Server.CreateObject("ADODB.Recordset")
'Conn.Provider = "ADsDSOObject"
'strconn = "Active Directory Provider"
conn.Open _
"Data Source=Active Directory Provider;Provider=ADsDSOObject"
strRS = "SELECT name, mail FROM 'LDAP://head.com' WHERE objectClass = 'user' "
Set RS = conn.Execute(strRS)
While RS.EOF = False
MsgBox ("Name: " & RS("name") & " ,e-mail: " & RS("mail"))
RS.MoveNext
Wend
End Sub
Something weird happed to the quotation in the above post, well i meant to quote this one anyhow. :o
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 :)
Re: How to retrieve All info about AD Users ??
Quote:
Originally Posted by
rambit
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:
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. ;)
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
Re: How to retrieve All info about AD Users ??
Quote:
Originally Posted by
rambit
May i ask if this is a possible method for listing all security groups on a user as well?
Declare some extra extra variables:
Change your Query to:
VB Code:
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:
Set RS = conn.Execute(strRS)
RS.MoveFirst
While RS.EOF = False
Set oUser = GetObject(RS("adsPath"))
For Each group In oUser.Groups
MsgBox group.Name
Next
RS.MoveNext
Wend
The group names are formatted like this "CN=<groupName>", just trim of the "CN=" part.
I'm not 100% sure if this is the only way to extract the groups but I hope this will work for you anyway.
Re: How to retrieve All info about AD Users ??
Thanks alot optional, it worked like a charm! :thumb:
best regards,
Rambit