Directory Services |
The IADsPathname::GetElement method retrieves an element of a directory path.
HRESULT GetElement( long lnElementIndex, BSTR* pbstrElement );
This method supports the standard return values, as well as the following:
For more information and other return values, see ADSI Error Codes.
Return Code | Description |
---|---|
S_OK | The operation succeeded. |
E_FAIL | The operation failed. |
ERROR_INVALID_INDEX | The supplied index does not exist. |
E_INVALIDARG | The supplied index is invalid. |
The following Visual Basic code example shows how to extract the first element of a path.
Dim x As New Pathname x.Set "LDAP://srv1/dc=dom,dc=company,dc=com", ADS_SETTYPE_FULL y = x.GetElement(0) ' y becomes "dc=dom".
The following VBScript code example shows how to extract the first element of a path.
Dim x Const ADS_SETTYPE_FULL = 1 Set x = CreateObject("Pathname") x.Set "LDAP://srv1/dc=dom,dc=company,dc=com", ADS_SETTYPE_FULL y = x.GetElement(0) ' y becomes "dc=dom".
The following C++ code example prints all the elements of a path. For more information and a code example of the GetPathnameObject function, see IADsPathname.
LPWSTR adsPath=L"LDAP://server/cn=jeffsmith,dc=Fabrikam,dc=com"; IADsPathname *pPath = GetPathnameObject(adsPath); long count=0; HRESULT hr = pPath->GetNumElements(&count); BSTR bstr; for (int I = 0; I<count; I++) { hr = pPath->GetElement(I,&bstr); printf("Element(%d): %S\n",bstr); SysFreeString(bstr); }
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.