| Platform SDK: Active Directory, ADSI, and Directory Services | 
The IADsNameTranslate interface is designed for translating distinguished names (DNs) among various formats as defined in the ADS_NAME_TYPE_ENUM enumeration. The feature is available to objects in Active Directory™.
Name translations are carried out on the directory server. To have a DN translated, you communicate with the server by means of a NameTranslate object, specifying which object is of interest and what format is desired. The general practice of applying IADsNameTranslate thus involves the following steps:
The IADsNameTranslate interface is implemented in an NameTranslate object that must be instantiated explicitly. The first step is to call the CoCreateInstance function in Visual C++, using the New operator in Visual Basic®, or invoking the CreateObject function in Visual Basic Scripting Edition. The example codes are given at the bottom of this page to demonstrate how to create the NameTranslate object in Visual C++, Visual Basic and VBScript/Active Server Pages.
| IUnknown Methods | Description | 
|---|---|
| QueryInterface | Returns pointers to supported interfaces. | 
| AddRef | Increments the reference count. | 
| Release | Decrements the reference count. | 
| IDispatch Methods | Description | 
|---|---|
| GetTypeInfoCount | Gets the number of type descriptions. | 
| GetTypeInfo | Gets a description of the object's programmable interface. | 
| GetIDsOfNames | Maps the name of the method or property to the DISPID. | 
| Invoke | Calls one of the object's methods or gets and sets one of its properties. | 
| IADsNameTranslate Property Methods | Description | 
|---|---|
| put_ChaseReferral | Turns referral chasing on or off. | 
| Init | Initializes the Name Translate object with default credentials. | 
| InitEx | Initializes the Name Translate object with specified credentials. | 
| Set | Specifies the object whose name is to be translated. | 
| Get | Gets the name of the object, set by Set, in a specified format. | 
| SetEx | Sets the names of multiple objects at the same time. | 
| GetEx | Gets the names of the objects, set by SetEx, in a specified format. | 
To create an instance of the NameTranslate object, you need to supply CLSID_NameTranslate as the class identifier and IID_IADsNameTranslate as the interface identifier when invoking the CoCreateInstance function.
IADsNameTranslate *pNto;
HRESULT hr;
hr = CoCreateInstance(CLSID_NameTranslate,
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      IID_IADsNameTranslate,
                      (void**)&pNto);
if(FAILED(hr)) { exit 1;}
 
hr = pNto->InitEx(ADS_NAME_INITTYPE_SERVER,
                  L"aDsServer",
                  L"aUser",
                  L"userDomain",
                  L"passwd");
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("Translation: %S\n", bstr);
 
SysFreeString(bstr);
pNto->Release();
Declare an object variable as "New NameTranslate" to create an instance of the NameTranslate object in a Visual Basic® application.
Dim nto as New NameTranslate dso="CN=jsmith, CN=users, DC=Microsoft dc=COM" nto.Init ADS_NAME_INITTYPE_SERVER, "aDsServer" nto.Set ADS_NAME_TYPE_1779, dso trans = nto.Get(ADS_NAME_TYPE_NT4) ' trans="Microsoft\jsmith"
Use CreateObject("NameTranslate") (or Server.CreateObject("NameTranslate") on an ASP page) to create an instance of the NameTranslate object in VBScript.
<%@ 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 = "aDsServer"
  user   = "jsmith"
  dom    = "Microsoft"
  passwd = "top secret" 
  dn = "CN=jsmith,CN=Users,DC=Microsoft,DC=COM" 
 
  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_NT4)
 
  Response.Write "<p>Translated name: " & result
 
%>
</body>
</html>
  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.
ADS_NAME_TYPE_ENUM, IADsNameTranslate Property Methods, IADsNameTranslate::Get, IADsNameTranslate::GetEx, IADsNameTranslate::Init, IADsNameTranslate::InitEx, IADsNameTranslate::Set, IADsNameTranslate::SetEx, CoCreateInstance