Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing information from active directory

11 views
Skip to first unread message

spnz

unread,
Oct 2, 2006, 6:00:01 AM10/2/06
to
Hi there,

Does anyone have a code example that gathers information from AD?

e.g. If I provide a persons logon name is it possible to provide details
like phone number etc etc and show the data in a messagebox or into a
document?


Any help would be really great!!

Thanks for your time!

Jay Freedman

unread,
Oct 2, 2006, 10:03:45 AM10/2/06
to
There is an "application programming interface" (API) for Active Directory.
It's called Active Directory Services Interface (ADSI), and there's quite a
lot of information about it on MSDN. Start at
http://msdn.microsoft.com/library/en-us/adsi/adsi/active_directory_service_interfaces_adsi.asp.

The following Office VBA macro displays the user's name and home directory.
Before pasting it into the VBA editor, go to Tools > References and put a
checkmark next to "Active DS Type Library".

Sub ADSI_demo()
Dim domainName As String, userName As String
Dim ADSuser As ActiveDs.IADsUser

domainName = InputBox("Domain:", "ADSI Demo")
If domainName = "" Then Exit Sub
userName = InputBox("User login:", "ADSI Demo")
If userName = "" Then Exit Sub

On Error GoTo noData
Set ADSuser = GetObject("WinNT://" & domainName & "/" & userName)
MsgBox ADSuser.FullName & vbCr & ADSuser.HomeDirectory
Set ADSuser = Nothing
Exit Sub

noData:
MsgBox Err.Number & vbCr & Err.Description
End Sub

You can experiment with the properties of the ADSuser variable -- for
example, delete ".HomeDirectory" and type the dot to get a popup list of all
the properties that are available, such as TelephoneNumber or
OfficeLocations. If your particular directory doesn't contain entries for
those properties, though, you'll get an error message when you try to
retrieve the data.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

spnz

unread,
Oct 10, 2006, 7:03:01 PM10/10/06
to
Thanks Jay that works great.

What about if I didn't have a userid but a full name instead, is it possible
to gather the same information without using a UserID??

Thanks again

Jay Freedman

unread,
Oct 10, 2006, 7:51:35 PM10/10/06
to
Sorry, I don't know the answer to your latest question. You've already
seen just about everything I know about AD. :-)

Try posting your question in the newsgroups
microsoft.public.active.directory.interfaces
(http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.active.directory.interfaces&cat=en_us_1265f606-89a9-4586-af70-a8d4b237b327&lang=en&cr=us)
and microsoft.public.windows.server.active_directory
(http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.server.active_directory&cat=en_us_5bd43452-4bab-4720-8df9-d5f37d3153b9&lang=en&cr=us).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

0 new messages