Platform SDK: Active Directory, ADSI, and Directory Services

Example Code for Binding to an Object Using ADsOpenObject

The following code fragment binds to an object with the name Bob in the Microsoft.com. The example uses secure authentication, but it does not specify any credentials, so it binds using the default credentials of the caller's security context.

[Visual Basic]
Dim np as IADsOpenDSObject
Dim myUser as IADs
 
Set np = GetObject("LDAP:")
Set myUser = np.OpenDSObject("LDAP://CN=Bob,DC=Microsoft,DC=com",vbNullString,vbNullString, ADS_SECURE_AUTHENTICATION)
[C++]
IADs *pObject;
HRESULT hr;
hr = ADsOpenObject(L"LDAP://CN=Bob,DC=Microsoft,DC=com", 
        NULL,
        NULL,
        ADS_SECURE_AUTHENTICATION,
        IID_IADs,
        (void**) &pObject);

If you set the fourth parameter to zero rather than specifying an authentication flag, ADSI performs a simple bind, which is sent as clear text. If you specify a user account and password without specifying authentication flags, they go over the network as clear text, which is a breach of security. Do not specify a user and password without also specifying authentication flags.