Platform SDK: Active Directory, ADSI, and Directory Services

IADsNameTranslate::Set

The IADsNameTranslate::Set method asks the directory service to set up a specified object for name translation. To set the names and format of multiple objects, use IADsnametranslate::SetEx.

HRESULT IADsNameTranslate::Set(
  long lnSetType,
  BSTR bstrADsPath
);

Parameters

lnSetType
The format of the name of a directory object. See ADS_NAME_TYPE_ENUM for more information.
bstrADsPath
The name of the object, for example, "CN=Administrator, CN=users, DC=Microsoft, DC=com".

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

Before calling this method to set the object name, you should have established a connection to the directory service using either IADsNameTranslate::Init or IADsNameTranslate::InitEx.

You can use the IADsNameTranslate::Set method to set name translation for objects residing on the directory server. When the referral chasing is on, this method will also set any object found on other servers. For more information on referral chasing, see IADsNameTranslate Property Methods.

Example Code [C++]

The following C/C++ code snippet uses the IADsNameTranslate::Set method to set an object so that its name can be translated from the RFC 1779 format to the Windows NT 4.0 user name format.

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=jsmith,cn=users,dc=Microsoft,dc=com");
if(FAILED(hr)) {exit 1;}
 
BSTR bstr;
hr = pNto->Get(ADS_NAME_TYPE_NT4, &bstr);
printf("Name in the translated format: %S\n", bstr);
 
SysFreeString(bstr);
pNto->Release();

Example Code [Visual Basic]

The following Visual Basic® code snippet uses the IADsNameTranslate::Set method to set an object so that its name can be translated from the RFC 1779 format to the Windows NT 4.0 user name format.

Dim nto as New NameTranslate
dso="CN=jsmith, CN=users, DC=Microsoft dc=COM"
 
nto.Init  ADS_NAME_INITTYPE_SERVER, "myServer"
nto.Set ADS_NAME_TYPE_1779, dso
trans = nto.Get(ADS_NAME_TYPE_NT4)   

Example Code [VBScript]

The following VBScript/ASP code snippet uses the IADsNameTranslate::Set method to set an object to have its name translated from the RFC 1779 format to the Windows NT 4.0 user name format.

<%@ Language=VBScript %>
<html>
<body>
<%
  Dim nto
  const ADS_NAME_INITTYPE_SERVER = 2  ' VBScript cannot read 
  const ADS_NAME_TYPE_1779 = 1        ' enumeration definition
  const ADS_NAME_TYPE_NT4 = 3
 
  dn = "CN=jsmith,CN=Users,DC=Microsoft,DC=COM" 
 
  Set nto = Server.CreateObject("NameTranslate")
  nto.Init ADS_NAME_INITTYPE_SERVER, "myServer"
  nto.Set ADS_NAME_TYPE_1779, dn
  result = nto.Get(ADS_NAME_TYPE_NT4)
 
  Response.Write "<p>Name in the translated format: " & 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 Property Methods, IADsNameTranslate::Init, IADsNameTranslate::InitEx, IADsNameTranslate::SetEx, ADS_NAME_TYPE_ENUM