Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsContainer::GetObject method obtains an IADs interface pointer to a directory object in the container. The object is identified by its schema class and the relative name.
HRESULT IADsContainer::GetObject( BSTR bstrClass, BSTR bstrRelativeName, IDispatch ** ppNamedObject );
If the schema class name is not provided, retrieve an interface pointer on the first object found in the container with the specified name.
This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.
The GetObject method is the most common way of retrieving an IADs interface pointer on an ADSI object.
The following Visual Basic code snippet gets a user object from a container object.
Dim cont As IADsContainer Dim usr As IADsUser Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com") Set usr = cont.GetObject("user", "jsmith")
This is equivalent to the more succinct and more efficient code:
Dim usr As IADsUser Set usr=GetObject("LDAP://CN=jsmith, OU=Sales,DC=Fabrikam,DC=com")
The following C++ code snippet gets a user object from a container object.
HRESULT hr; CoInitialize(NULL); IADsContainer *pCont=NULL; hr = ADsGetObject(L"LDAP://DC=windows2000,DC=nttest,DC=microsoft,DC=com", IID_IADsContainer, (void**) &pCont ); ////////////////////////////////////////////////////////////////////// // Get the child from the container. // Note in the LDAP provider you can go down more than one level. ////////////////////////////////////////////////////////////////////// IDispatch *pDisp = NULL; IADs *pADs = NULL; hr = pCont->GetObject(L"user", L"CN=Mike Smith, OU=DSys", &pDisp ); pCont->Release(); hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs ); pDisp->Release(); // Do something with pADs here. pADs->Release(); CoUninitialize();
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 Iads.h.
ADsGetObject, IADs, IADs::get_Class, IADs::get_Name, IADsContainer, IDispatch