Platform SDK: Active Directory, ADSI, and Directory Services

GetObject

Use the GetObject function in languages that support Automation to retrieve a COM moniker. The GetObject function takes a moniker string. When using ADSI, the binding string is the moniker string. For example:

Dim x As IADs
Set x = GetObject("LDAP://DC=NorthAmerica,DC=Microsoft,DC=com")

and another example:

The following example shows how to bind 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/CN=MarySmith,DC=Microsoft")
 

The GetObject function will bind to the specified object on behalf of the current user.

If you are using Microsoft® Visual C++®, or other C/C++ compilers, ADSI provides a helper function called ADsGetObject. In addition to the moniker string, this function accepts additional parameters discussed shortly. Alternatively, you can use COM's MkParseDisplayName or MkParseDisplayNameEx to achieve the same result as GetObject in Visual Basic. For example:

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 the Visual Basic GetObject function to obtain a pointer or 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.