Title: Usings ADSI to Access Exchange
1Using ADSI To Access The Exchange 5.5
Directory Tom Rizzo Thomriz_at_microsoft.comMicroso
ft Corporation
2(No Transcript)
3Agenda
- Overview of ADSI architecture
- Programming with ADSI
- Binding to a DS object
- Reading and writing properties
- Searching
- Creating new Mailboxes
- Demonstrations
- Questions
4Introduction To Active Directory Service
Interfaces
- ADSI is the Microsoft strategic API to the
Active Directory - Windows 2000 Active Directory supports ADSI
- Simplified and uniform manipulation of DS objects
in a heterogeneous environment - Ease of use for cross-language development
- Visual Basic, Java, Visual C, Visual C
5ADSI ArchitectureLeaf component object
- IADs
- Dual-interface
- On all ADSI objects
- Name and class
- Path and link to parent
- Link to schema
- Property caching
- IADsUser
- User-specific properties
- IDispatch
- Name-bound access
E.g., user object
IADs
IADsOU
IDispatch
6ADSI ArchitectureContainer component object
- IADsContainer
- Dual-interface
- Found on allDS containers
- Enumeration
- Life cycle (Create, Delete, CopyHere, MoveHere)
E.g., organizational unit object
IADs
IADsOU
IADsContainer
IDispatch
7Viewing Exchange Schema
- Run Exchange in Raw Mode
- Select View.Raw Directory
8Other Tools For ADSI
- You can also use ADSI Browser or LDP to view
Exchange schema - Schema is super important
- Access-Category is important as well
- 0 System only
- 1 Modify Admin Attributes
- 2 Modify User Attributes
- 3 Modify Permissions
- Eg. Phone number is Access-Category 2
9Common Object Classes
- Mail-Recipient (person)
- Mailbox (organizationalPerson)
- Custom-Recipient (custom-recipient)
- Distribution-List (groupOfNames)
Object class names are modifiable using Exchange
Admin in raw mode
10Doing Useful Work With ADSI
- You need
- A supported programming language like Java,
Visual Basic, Visual C, Visual C - An interface pointer to IADs
- And away you go!
11Programming With ADSIIADs
- Implemented by every base object
- Properties
- Name, ADsPath, class, schema, parent
- Methods
- Get, put, getinfo, setinfo
- Using only the IADs interface you can learn all
about an object and get or set all of its
properties
12Getting An Interface PointerWhen you know the
object name
- GetObject(ADsPath)
- From Java, Visual Basic, Visual Basic for
Applications, Visual Basic Scripting Edition - ADsGetObject(ADsPath,riid,pObj)
- From Visual C, Visual C, etc.
- ADs pathltprovidergt//ltprovider-specific-stringgt
- For example LDAP//ServerAddress/CUS/OMicroso
ft/OUAccounting/CNJamesSmith
13Getting Objects
- OpenDSObject(Path, username, password,
authentication) - Make sure that the path is a valid path
- Username should be in the format cnUsername
- To get hidden items/PFs, add cnadmin to the end
of your username
14Binding An Object
- Example 1Binding a DS object, reading and
writing properties using LDAP
15Reading AndWriting Properties
- Simple caching system
- IADsGetInfo()
- Reloads the cache with values from the
underlying store - Changes made in the cache are lost
- IADsSetInfo()
- Writes cached changesto the underlying store
16What About Individual Props?
- Use Put and Get for simple properties
- For multi-value properties, you need to use GetEx
and PutEx - After setting properties, always call SetInfo!
17Binding To An ObjectVisual Basic code snippet
Set objADsExchDL _ GetObject("LDAP//MR53CPU1/cn
SampleDL,cn" _ Recipients,ouMR53,oMicrosoft")
MsgBox "Owner " objADsExchDL.Owner
18Reading Properties Visual Basic code snippet
strPathADsExchConfig _ "LDAP//MR53CPU1/cnMicro
soft Private MDB," _ "cnWashington,cnServers,
" _ "cnConfiguration,ouEurope,oTailspin
Toys " Set objADsExchConfig _ GetObject(strPath
ADsExchConfig) objADsExchConfig.GetInfo strConfig
Mail objADsExchConfig.Get("mail")
19Writing Properties Visual Basic code snippet
Set objADsExchRecipients _ GetObject("LDAP//Was
hinton/" _ "cnRecipients,ouEurope,oTailspin
Toys") Set objADsExchDL _ objADsExchRecipients
.Create _ ("groupOfNames", "cn"
CStr(pstrAlias)) ' Set properties objADsExchDL.P
ut "cn", CStr(pstrDispName) objADsExchDL.Put
"uid", CStr(pstrAlias)
20Manipulating Objects
- Example 2
- Simple object manipulationCreatingDeleting
21Manipulating Objects
Dim MyContainer As IADsContainer Bind to
container object Set MyContainer
_ GetObject("LDAP//MyLdapSvr/OInternet" _
"/DCRedmond") Create a child object MyChildObjec
t MyContainer.Create _ ("User",
"CNMyUser") Set mandatory properties
MyChildObject.Put("samAccountName", "MyUser")
Commit the child object MyChildObject.SetInfo N
ow delete the child object MyContainer.Delete("Use
r", "CNMyUser")
22Object Enumeration
- Example 3Discovering a container and
recursively enumerating the contents
23Enumerating A Container Visual Basic code snippet
Private Sub cmdEnum_Click() Dim MyContainer As
IADsContainer 'Bind to container object Set
MyContainer GetObject("LDAP//Washington/ouEuro
pe" _ ",oTailspin Toys") 'Enumerate child
objects For Each Object In MyContainer
Debug.Print Object.ADsPath Next End Sub
24Searching The Directory
- Example 4Searching the Exchange Directory via
ADSI
25Searching The Directory Visual Basic ADO script
Set conn CreateObject("ADODB.Connection") conn.O
pen "ProviderADSDSOObject Set rsSel
conn.Execute(strQuery) ADS_cSel
rsSel.RecordCount While Not rsSel.EOF For i 0
To rsSel.Fields.Count - 1 Debug.Print
CStr(rsSel.Fields(I)) Next i
rsSel.MoveNext Wend
26Querying A Directory
strQuery "ltLDAP//Washington/cnRecipients,ouEru
ope,_ "oTailspin Toysgt" _ "((cnM)(!(objectC
lassgroupOfNames)))"_ "cn,adspath,uidOneLevel"
- The root node of a search
- String that specifies criteria
- Identifies attributes of interest
- Beginning entry point, Base, OneLevel or SubTree
- Base DN ltLDAP
- Filter ((cnM)
- Property List cn,adspath,uid
- Scope OneLevel
27Create Mailboxes
- Use ADSI to
- Create the mailbox
- Use AcctCrtlibrary to
- Associate NT account
- Set permissions on mailbox
28GAL Modify Example
29GAL Modify Example Find user
Set ADOconn CreateObject("ADODB.Connection") ADO
conn.Provider "ADSDSOObject" ADOconn.Open "ADs
Provider" bstrADOQueryString "ltLDAP//"
bstrServer _ "gt((objectClassorganizationalPer
son)" _ "(cn" bstrSearchCriteria "))"
_ "cn,adspathsubtree" Set objRS _
ADOconn.Execute(bstrADOQueryString)
30GAL Modify Example Modify data
Sub ModifyProperty (bstrNewValue,
bstrADsProperty) If Len(bstrNewValue) ltgt 0
Then objIADs.Put bstrADsProperty,
CStr(bstrNewValue) Else objIADs.Get(bstrADsP
roperty) If Err.Number 0 Then
objIADs.PutEx ADS_PROPERTY_CLEAR,_ bstrADsPropert
y, CStr(" ") End If Err.Clear End
If End Sub
31Update DL Example
32Summary
- Benefits of ADSI
- Easy to write Directory Service-enabled
applications! - Single API for many namespaces
- Cross-language support
- Reduced development cost
- Single set of management applications
- Reduced learning curve
33Summary
- Prepare for the Window 2000 Active Directory by
using the Exchange 5.5 directory and ADSI today - ADSI provides simple, uniform directory object
manipulation in a heterogeneous environment
34Additional Resources
- http//msdn.microsoft.com/exchange
- Http//www.microsoft.com/exchange
- http//www.microsoft.com/windows/server/Technical/
directory/default.asp - http//www.microsoft.com/windows/server/Technical/
directory/adsilinks.asp - Programming Microsoft Outlook and Exchange
(MSPRESS)
35Questions?
36(No Transcript)