Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Exchange address book 1

Status
Not open for further replies.

BobTheMad

Programmer
Jun 11, 1999
81
US
I am developing an application that needs to access my company's Exchange server global address book in order to get a list of valid names. What would be the easiest way to accomplish this?

Thanks in advance.

Thought for the day: Beware of Gods who cannot laugh...
 
Any ideas?

Thanks...

Thought for the day: Beware of Gods who cannot laugh...
 
Use CDO 1.21; it isn't installed by default if Outlook 2000 or later and has to be selected during a custom install.
Code:
Dim objSession As MAPI.Session
Dim objAddrList As MAPI.AddressList
Dim objAddrEntries As MAPI.AddressEntries
Dim objAddrEntry As MAPI.AddressEntry

Set objSession = CreateObject("MAPI.Session")
'In a real app, read the default profile from the registry
'and pass it to the Logon method so the logon dialog isn't displayed
objSession.Logon
Set objAddrList = objSession.AddressLists("Global Address List")
Set objAddrEntries = objAddrList.AddressEntries
Set objAddrEntry = objAddrEntries.GetFirst
Do Until objAddrEntry Is Nothing
  If objAddrEntry.DisplayType = CdoUser Then
    'Just list users, exclude distribution lists etc
    Debug.Print objAddrEntry.Name
  End If
  Set objAddrEntry = objAddrEntries.GetNext
Loop

Set objAddrEntry = Nothing
Set objAddrEntries = Nothing
Set objAddrList = Nothing
Set objAddrSession = Nothing
Paul Bent
Northwind IT Systems
 
That works perfectly... Thanks!

Thought for the day: Beware of Gods who cannot laugh...
 
One further question... what registry key needs to be accessed to get the logged-in user's Exchange profile name?

Thought for the day: Beware of Gods who cannot laugh...
 
W95/98/ME: HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles

NT/2000/XP: HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles

Read the value name, DefaultProfile

Paul Bent
Northwind IT Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top