Directory Services

IADsNameTranslate::Get

The IADsNameTranslate::Get method retrieves the name of a directory object in the specified format. The distinguished name must have been set in the appropriate format by the IADsNameTranslate::Set method.

HRESULT Get( 
  long lnFormatType,
  BSTR* pbstrADsPath
);

Parameters

lnFormatType
The format type of the output name. For more information, see ADS_NAME_TYPE_ENUM. This method does not support the ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME element in ADS_NAME_TYPE_ENUM.
pbstrADsPath
The name of the returned object.

Return Values

This method supports the standard HRESULT return values, including:
Return Code Description
S_OK The name has been set successfully.
E_FAIL The operation failed.
E_OUTOFMEMORY A memory allocation failure occurred.
E_ADS_BAD_PARAMETER One or more parameters are invalid.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_RESOLVING) Cannot resolve the name.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_NOT_FOUND) The name cannot be found or the caller does not have permission to access the name.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_NOT_UNIQUE) The input name is mapped to more than one output name or the desired format did not have a single, unique value for the object found.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_NO_MAPPING) The input name was found, but the associated output format cannot be found.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_DOMAIN_ONLY) Unable to resolve the entire name, but the domain in which the object resides could be determined.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING) A syntactical mapping cannot be performed on the client without going out over the network.
HRESULT_FROM_WIN32(ERROR_DS_NAME_ERROR_TRUST_REFERRAL) The name is from an external trusted forest.

Remarks

This method lets you retrieve the name of a single directory object. To retrieve names of multiple objects use IADsNameTranslate::GetEx.

When referral chasing is on, this method will attempt to chase and resolve the path of a specified object that is not residing on the connected server.

Example Code [C++]

The following C/C++ code example shows how to translate a distinguished name that is compliant with RFC 1779 to a GUID format. The computer name of the directory server is "myServer".

IADsNameTranslate *pNto;
HRESULT hr;
hr = CoCreateInstance(CLSID_NameTranslate,
					NULL,
					CLSCTX_INPROC_SERVER,
					IID_IADsNameTranslate,
					(void**)&pNto);
if(FAILED(hr)) { exit 1;}
 
hr = pNto->Init(ADS_NAME_INITTYPE_SERVER,
				CComBSTR("myServer"));
if (FAILED(hr)) { exit 1;}
 
hr =pNto->Set(ADS_NAME_TYPE_1779, CComBSTR("CN=jeff,CN=Users,DC=myDomain,DC=Fabrikam,DC=COM,O=Internet"));
if(FAILED(hr)) {exit 1;}
 
BSTR bstr;
hr = pNto->Get(ADS_NAME_TYPE_GUID, &bstr);
printf("Translation: %S\n", bstr);
 
SysFreeString(bstr);
pNto->Release();

Example Code [Visual Basic]

The following Visual Basic code example shows how to translate a distinguished name that is compliant RFC 1779 to a GUID format. The computer name of the directory server is "myServer".

Dim nto As New NameTranslate
Dim result As String
 
dn = "CN=rob,CN=Users,DC=myDomain,DC=Fabrikam,DC=COM,O=Internet" 
nto.Init ADS_NAME_INITTYPE_SERVER, "myServer"
nto.Set ADS_NAME_TYPE_1779, dn
result = nto.Get ADS_NAME_TYPE_GUID
MsgBox result

Example Code [VBScript]

The following VBScript/ASP code example shows how to translate a distinguished name that is compliant with RFC 1779 to a GUID format. The machine name of the directory server is "myServer".

<%@ Language=VBScript %>
<html>
<body>
<%
  Dim nto
  const ADS_NAME_INITTYPE_SERVER = 2
  const ADS_NAME_TYPE_1779 = 1
  const ADS_NAME_TYPE_NT4 = 3
 
  server = "myServer"
  user   = "jeffsmith"
  dom	= "Fabrikam"
  passwd = "top secret" 
 
  Set nto = Server.CreateObject("NameTranslate")
  nto.InitEx ADS_NAME_INITTYPE_SERVER, server, user, dom, passwd
  nto.Set ADS_NAME_TYPE_1779, dn
  result = nto.Get(ADS_NAME_TYPE_GUID)
 
  Response.Write "<p>Translated name: " & result
 
%>
</body>
</html>

Requirements

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.

See Also

IADsNameTranslate, IADsNameTranslate::GetEx, IADsNameTranslate::Set, ADS_NAME_TYPE_ENUM