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!

Re: Accessing information from active directory by Jay

Jay
Mon Oct 02 09:03:45 CDT 2006

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 wrote:
> 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!



Re: Accessing information from active directory by spnz

spnz
Tue Oct 10 18:03:01 CDT 2006

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" wrote:

> 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 wrote:
> > 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!
>
>
>

Re: Accessing information from active directory by Jay

Jay
Tue Oct 10 18:51:35 CDT 2006

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.

On Tue, 10 Oct 2006 16:03:01 -0700, spnz
<spnz@discussions.microsoft.com> wrote:

>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" wrote:
>
>> 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 wrote:
>> > 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!
>>
>>
>>