Binding to an Object

Binding to a directory object through ADSI is simple. In languages that support Automation, such as Java or Visual Basic®, use the GetObject function with a fully specified ADsPath.

Binding to user objects from different directory services
Dim MyObject1 As IADsUser
Dim MyObject2 As IADsUser
Set MyObject1 = GetObject("WinNT://MyDomain/MyAccount,User")
Set MyObject2 = GetObject("LDAP://MyLdapSvr/O=Internet/DC=Redmond/CN=MarySmith")
 

In C or C++, the binding looks very similar:

IADsUser *pMyObject1, *pMyObject2;
ADsGetObject(TEXT("WinNT://MyDomain/MyAccount,User"),
              IID_IADsUser,
              (void) ** &pMyObject1);
ADsGetObject(TEXT(
              "LDAP://MyLdapSvr/O=Internet/DC=Redmond/CN=MarySmith"),
              IID_IADsUser,
              (void) ** &pMyObject2);
 

In each case, the client application calls either ADsGetObject or Visual Basic® GetObject to obtain a pointer or a reference respectively, to an interface on an ADSI object that represents an end-user.

ADSI uses the ProgID in the first part of the string to load the appropriate ADSI provider DLL to process the bind request.

When credentials need to be established when passing a bind request to a directory service, you can use ADsOpenObject. In Automation environments, the Namespace object supports the IADsOpenDSObject interface to supply the same functionality.

The following Visual Basic code fragment supplies credentials when binding to an object:

Dim MyObject as Object
Dim MyNamespace as IADsOpenDSObject
 
Set MyNamespace = GetObject("LDAP:")
Set MyObject = MyNamespace.OpenDSObject("LDAP://MyLdapSvr/O=Internet",
       "Mary Smith","LandOfOz",0x1);
 

C and C++ programmers can use ADsOpenObject as shown below:

hr = ADsOpenObject(

LDAP://MyLdapSvr/O=Internet,

"Mary Smith",

"LandOfOz",

0x1,

IID_IADs,

(void **)&pIADs

);

For more information, see ADSI Component Interaction.