Platform SDK: Active Directory, ADSI, and Directory Services |
The ADsOpenObject function binds to an ADSI object using explicit username and password credentials.
HRESULT ADsOpenObject( LPWSTR lpszPathName, LPWSTR lpszUserName, LPWSTR lpszPassword, DWORD dwReserved, REFIID riid, VOID FAR * FAR *ppObject );
This method supports the standard HRESULT return values, including:
For other return values, see ADSI Error Codes.
A C/C++ client calls the ADsOpenObject helper function to bind to an ADSI object, using the user name and password supplied as credentials for the appropriate directory service. If lpszUsername and lpszPassword are NULL and ADS_SECURE_AUTHENTICATION is set, ADSI binds to the object using the security context of the calling thread, which is either the security context of the user account under which the application is running or of the client user account that the calling thread is impersonating.
The ADsOpenObject function ignores the dwReserved flag when attempting to bind to an NDS or NWCOMPAT object.
To work with the WinNT: provider, you can pass in lpszUserName as one of the following strings:
With the LDAP provider for Active Directory, you may pass in lpszUserName as one of the following strings:
The following code snippet illustrates how to bind to a directory service object with the user credential of jsmith.
IADs *pObject; HRESULT hr; hr = ADsOpenObject(L"LDAP://CN=Bob,DC=Fabrikam,DC=com", "jsmith", "etercespot", ADS_SECURE_AUTHENTICATION, IID_IADs, (void**) &pObject);
This function is equivalent to the IADsOpenDSObject::OpenDsObject method.
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
Windows 95/98: Requires Windows 95 or later (with DSClient).
Header: Declared in Adshlp.h.
Library: Included as a resource in ActiveDs.dll.
ADSI Error Codes, ADSI Functions, IADsOpenDSObject, IADsOpenDSObject::OpenDsObject