Platform SDK: Active Directory, ADSI, and Directory Services

ADS_NAME_INITTYPE_ENUM

The ADS_NAME_INITTYPE_ENUM enumeration specifies the types of initialization to perform on a NameTranslate object. It is used in the IADsNameTranslate interface.

enum {
  ADS_NAME_INITTYPE_DOMAIN   = 1,
  ADS_NAME_INITTYPE_SERVER   = 2,
  ADS_NAME_INITTYPE_GC       = 3
  } ADS_NAME_INITTYPE_ENUM;

Elements

ADS_NAME_INITTYPE_DOMAIN
Initializes a NameTranslate object by setting the domain that the object will bind to.
ADS_NAME_INITTYPE_SERVER
Initializes a NameTranslate object by setting the server that the object will bind to.
ADS_NAME_INITTYPE_GC
Initializes a NameTranslate object by locating the global catalog that the object will bind to.

Remarks

The IADsNameTranslate::Init method or IADsNameTranslate::InitEx method uses these options to initialize the NameTranslate object. When ADS_NAME_INITTYPE_SERVER is used, you will need to specify the machine name of a directory server. When ADS_NAME_INITTYPE_DOMAIN is set, you must supply the domain name within a directory forest. When ADS_NAME_INITTYPE_GC is issued, the second parameter in IADsNameTranslate::Init or IADsNameTranslate::InitEx is ignored. The Global Catalog server of the domain of the current machine will be used to carry out the name translate operations. The initialization will fail if the host machine is not part of a domain because no global catalog will be found in such a scenario.

Note  Because VBScript cannot read information from a type library, VBScript applications do not understand the symbolic constants as defined above. You should use the numerical constants instead to set the appropriate flags in your VBScript applications. If you want to use the symbolic constants as a good programming practice, you should make explicit declarations of such constants, as done here, in your VBScript applications.

Example Code [C++]

The following C/C++ code snippet uses IADsNameTranslate::Init method to initialize a NameTranslate object through the global catalog, assuming the client running the application is within the directory forest. It then renders the distinguished name of a user object in the Windows NT 4 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_GC, L"");
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 IADsNameTranslate::Init method to initialize a NameTranslate object through the global catalog, assuming the client running the application is within the directory forest. It then renders the distinguished name of a user object in the Windows NT 4 format.

Dim nto as New NameTranslate
dso="CN=jsmith, CN=users, DC=Microsoft dc=COM"
 
nto.Init  ADS_NAME_INITTYPE_GC, ""
nto.Set ADS_NAME_TYPE_1779, dso
trans = nto.Get(ADS_NAME_TYPE_NT4)   
MsgBox "Translated name = " & trans

Example Code [VBScript]

The following VBScript/ASP code snippet uses IADsNameTranslate::Init method to initialize a NameTranslate object through the global catalog, assuming the client running the application is within the directory forest. It then renders the distinguished name of a user object in the Windows NT 4 format.

<%@ Language=VBScript %>
<html>
<body>
<%
  Dim nto
  const ADS_NAME_INITTYPE_GC = 3  ' VBScript cannot read 
  const ADS_NAME_TYPE_1779 = 1        ' enumeration definition
  const ADS_NAME_TYPE_NT4 = 3
 
  dn = "CN=john smith,CN=Users,DC=Microsoft,DC=COM" 
 
  Set nto = Server.CreateObject("NameTranslate")
  nto.Init ADS_NAME_INITTYPE_GC, ""
  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

ADSI Enumerations, IADsNameTranslate