| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsCollection::GetObject method retrieves an item of the collection.
HRESULT IADsCollection::GetObject( BSTR bstrName, VARIANT pvarItem );
This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.
If you know the name of a session in the Sessions collection, you can call the IADsCollection::GetObject method explicitly to retrieve the session object.
The following Visual Basic code snippet shows how to retrieve a named session object (mySession) from a collection of active file service sessions.
Dim fso as IADsFileServiceOperations
Dim ses as IADsSession
Dim coll as IADsCollection
Set fso = GetObject("WinNT://myComputer/LanmanServer")
Set coll = fso.Sessions
' The following statement invokes IADsCollection::GetObject.
Set ses = coll.GetObject(mySessionName)
The following C++/C code snippet shows how to retrive a named session object (mySession) from a collection of active file service sessions.
HRESULT GetASessionObjectFromCollection(LPWSTR mySession)
{
LPWSTR adspath = L"WinNT://myComputer/LanmanServer";
IUnknown *pUnk=NULL;
HRESULT hr;
IADsCollection *pColl;
IADsFileServiceOperations *pFso;
hr = ADsGetObject(adspath,
IID_IADsFileServiceOperations,
(void**)&pFso);
if(FAILED(hr)) return hr;
hr = pFso->Sessions(&pColl);
if(FAILED(hr)) return hr;
pFso->Release();
VARIANT varObj;
VariantInit(&varObj);
hr = pColl->GetObject(mySession &varObj);
IADs *pADsObj;
V_DISPATCH(&varObj)->QueryInterface(IID_IADs,(void**)&pADsObj);
BSTR bstrObj;
hr = pADsObj->get_Class(&bstrObj);
printf("Class of the object obtained from GetObject: %S\n",
bstrObj);
SysFreeString(bstrObj);
VariantClear(&varObj);
pADsObj->Release();
pColl->Release();
return S_OK;
}
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.