Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsPathname::GetElement method retrieves an element of a directory path.
HRESULT IADsPathname::GetElement( DWORD dwElementIndex, BSTR *pbstrElement );
This method supports the standard return values, as well as the following:
For other return values, see ADSI Error Codes.
The following Visual Basic® code snippet shows how to extract the first element of a pathname.
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 snippet shows how to extract the first element of a pathname.
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 snippet prints out all the elements of a path. See the code snippet in IADsPathname for the GetPathnameObject function.
LPWSTR adsPath=L"LDAP://server/cn=jsmith,dc=Microsoft,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); }
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.