Platform SDK: Active Directory, ADSI, and 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 IADsNameTranslate::Get(
  long lnFormatType,
  BSTR *pbstrADsPath
);

Parameters

lnFormatType
The format type of the output name. See ADS_NAME_TYPE_ENUM for more information.
pbstrADsPath
The name of the object returned.

Return Values

This method supports the standard HRESULT return values, including:

S_OK
The name has been set successfully.
E_ADS_DSNAME_ERROR_RESOLVING
Cannot resolve the name.
E_ADS_DSNAME_ERROR_NOT_FOUND
Cannot find the name.
E_ADS_DSNAME_ERROR_NOT_UNIQUE
The name is not unique.
E_ADS_DSNAME_ERROR_NO_MAPPING
Cannot map the name.
E_ADS_DSNAME_ERROR_DOMAIN_ONLY
Can resolve the domain, but not the entire path.
E_FAIL
The operation has failed.
E_OUTOFMEMORY
The name cannot be set.

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 snippet illustrates 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".

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,
                  L"myServer");
if (FAILED(hr)) { exit 1;}
 
hr =pNto->Set(ADS_NAME_TYPE_1779, L"CN=rob,CN=Users,DC=myDomain,DC=Microsoft,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 snippet illustrates how to translate a distinguished name that is compliant RFC 1779 to a GUID format. The machine name of the directory server is "myServer".

Dim nto As New NameTranslate
Dim result As String
 
dn = "CN=rob,CN=Users,DC=myDomain,DC=Microsoft,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 snippet illustrates 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   = "jsmith"
  dom    = "Microsoft"
  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

  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.

See Also

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