![]() |
||
![]() |
![]() |
|
For the latest update on Active Directory® programming, please visit: http://msdn.microsoft.com/developer/windows2000/adsi/actdirguide.asp The primary purpose of this page is to give you a jump start on Active Directory programming. For more detailed programming topics, please visit the above link. For quick illustrations and better reading, the samples are in Visual Basic®. For Visual C++® programmers, the Active Directory Programmer's Guide provides plenty of C++ samples. Requirements
What do I lose if I don't have a Windows 2000 client?
With the upcoming DS Client package for Windows 95/Windows 98, these limitations will be removed. Bind
Get/Modify data
You can quickly browse the Active Directory using the ADSVW.EXE shipped with the SDK. If your client is Windows NT 4.0 or Windows 95/Windows 98, then you'll need to know the server name or domain DNS name that hosts Active Directory.
If your client is Windows 2000, and you're authenticated by Active Directory, you do not need to specify the server name. Now you should be able to browse Active Directory. Go to top.
The LDAP standard (RFC 2251) requires that all LDAP directories maintain a special entry, called the Root DS Entry, or Root DSE. This entry provides a set of standard operational attributes that the user can read to find out fundamental characteristics of the directory and the server. The Root DSE can also provide any number of vendor-specific attributes. One of the standard operational attributes is "defaultNamingContext". This attribute contains the distinguished name (DN) of the root of the directory. In Windows 2000, this is the DN of the Domain container at the root of the current tree. By reading the defaultNamingContext attribute from the Root DSE, you can discover what domain you are logged in to at run time. ADSI provides a special mechanism for binding to the root DSE: using the ADSpath "LDAP://RootDSE". VB: set myObj = GetObject("LDAP://RootDSE") VC: hr = AdsGetObject(L"LDAP://RootDSE", IID_IADs,(void **)&pDSObj); Write a program that reads the defaultNamingContext attribute from
the Root DSE to discover what domain you are logged into. Go to top.
Binding with
an Alternate Credential ADSI binds to the directory using the credentials of the currently logged-in user. Sometimes you need to bind to a particular directory service using specific credentials, or using credentials that are different from those of the logged-in user. ADSI provides an interface and method to provide this functionality. The namespace object supports the IADsOpenDSObject interface, which has a single method, OpenDSObject. OpenDSObject takes as arguments the ADSpath of the object or subtree to bind to, the username, the password, and the authentication method. To obtain the IADsOpenDSObject interface, perform a default bind to "LDAP:". VB: set dso = Getobject("LDAP:") VC: hr = AdsGetObject(TEXT("LDAP:"),IID_IADsOpenDSObject,(void **)&pDSObj); HRESULT OpenDsObject(LPTSTR Path, LPTSTR User,lpszPAssword,LONG Auth,Idispatch** ppDispatch) Use ADS_SECURE_AUTHENTICATION for secured authentication (NTLM or Kerberos). Write a program that discovers the current domain, then bind to it with explicit credentials. Source code can be found in \samples\ActiveDir\RootDSE\VC. Go to top.
You can bind the Active Directory current domain using the entry found in the RootDSE. Domain information is shared only in that domain. Example: Go to top.
Binding to the Schema Container You can bind to the Active Directory Schema
container using the entry found in the RootDSE. Schema information is shared
across the forest. Go to top.
Binding to the Configuration Container You can bind the Active Directory
Configuration Container using the entry found in the RootDSE. Data in the
configuration partition is replicated across forest. Go to top.
NOTE: You must have
a computer that runs Windows 2000 in order to execute this sample.
Write a program that discovers the DN of the current domain, user, and computer. The version of ADSI that is shipped with Windows 2000 also provides a new interface, IADsADSystemInfo, that allows you to do this same task. Go to top.
Binding with GUID Example:
or
For a Visual C++ sample, click here. Go to top.
Every security principal object (such as users, groups, computers) has a SID. You can bind to that object based on the SID. Example:
Go to top.
You can bind to the global catalog using GC: as the provider. To bind to the GC with a forest scope, you need to know a server name, or a domain DNS name in a forest. Optionally, you can manually enumerate the GC.
----OR---- enumerate manually
To bind to the GC with a tree scope, you need to know the tree's distinguished name:
To bind to GC with a domain scope, you need to know the domain's distinguished name:
Go to top. Active Directory can operate in two modes. Native mode where all domain controllers are Windows 2000 servers, or mixed mode, where the backup domain controllers can be a mix of Windows NT 4.0 servers and Windows 2000 servers. The administrator must explicitly upgrade the domain mode. To find out the current domain mode, use the following code snippet:
Go to top.
Listing Attributes that are Replicated to GC Only selected attributes are replicated to a GC. To find out which ones are replicated, search from the Schema container, then use either ADO or IDirectorySearch (for C++) with the following LDAP filter:
Go to top.
An indexed attribute is useful for quick searches. To find out all indexed attributes, you can bind to the Schema container using either ADO or IDirectorySearch (for C++) with the following LDAP filter.
The indexed attribute is the attribute with the 0x00000001 bit set. Go to top.
You can optionally choose UPN suffixes for your company. This list will appear on the Administrator Tool when composing a User Principal Name during user creation.
Go to top.
It's recommended that you display a canonical name to the user instead of a distinguished name. A canonical name (or friendly name) is in the form of dnsDomainName/objectPath. For example, if the DN is CN=JSmith, OU=Marketing, OU=DSys, DC=ArcadiaBay, DC=Com, then its canonical name is arcadiayBay.com/dsys/marketing/jsmith. Active Directory supports an operational attribute that returns a canonized name. The attribute name is 'canonicalName'. To obtain an operational attribute, you can either use IDirectoryObject/IDirectorySearch (for VC++), or IADs::GetInfo (for VB and VC++). Example:
For Windows 2000, another option is to use IADsNameTranslate. Go to top.
Creating an Organizational Unit To create an organizational unit, you need to know the parent container's distinguished name.
To create an organizational unit in a current domain, you can use the following code:
Go to top
A user normally lives in an organizational unit. To create a user, you'll need to supply the organizational unit and down-level user name, at the minimum.
Go to top.
You can create a group or distribution list in Active Directory. Group can be either a domain local, global, or universal group. For more information about group, please follow the Active Directory Programmer's Guide.
Go to top.
Delegating an Organizational Unit Now that you have set up an organizational unit and created a user, you can delegate this organizational unit to the user. In our scenario, we will delegate the Marketing organizational unit to James Smith, so that he can create and delete users. We will need to retrieve the security descriptor of that organizational unit and set the appropriate permission for James Smith.
Go to top.
Use IADsDeleteOps to delete a subtree of Active Directory objects.
Go to top.
Ambiguous Name Resolution (ANR) Searching The LDAP filter for ANR searching is (anr=yourSearch). For example (anr=John). Go to top.
Listing All Attributes Used in ANR Searches Bind to the Schema container and ADO or IDirectoryobject to perform a search. All attributes that have the 0x00000004 bit set on the attributeSchema object are included in the ANR query evaluations.
Go to top.
'----CONSTANTS----
'----PARAMETERS ----
'----BUILD WELL-KNOWN GUID ADSPATH FOR COMPUTER CONTAINER----
'----CREATE A COMPUTER OBJECT----
'----SET INITIAL PASSWORD----
'----SET SECURITY----
'----SET ACE----
'----ACL----
'----SD----
'----ENABLE THE ACCOUNT----
Go to top
|