Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsNameTranslate::Init method initializes a name translate object by binding to a specified directory server, domain, or global catalog, using the credentials of the currently logged on user. To initialize the object with a different user credential, use IADsNameTranslate::InitEx.
HRESULT IADsNameTranslate::Init( long lnInitType, BSTR bstrADsPath );
This method supports the standard HRESULT return values, including:
After the successful initialization, you can proceed to use the name translate object to submit requests of name translations of objects in the directory. For more information, see IADsNameTranslate::Set, or IADsNameTranslate::Get.
The following C/C++ code snippet uses the IADsNameTranslate::Init method to initialize a NameTranslate object before the distinguished name of a user object is rendered in the Windows NTŪ 4.0 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();
The following Visual BasicŪ code snippet uses the IADsNameTranslate::Init method to initialize the NameTranslate object in order to have the distinguished name of a user object rendered in 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)
The following VBScript/ASP code snippet uses the IADsNameTranslate::Init method to initialize the NameTranslate object in order to have the distinguished name of a user object rendered in 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>
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.
IADsNameTranslate, IADsNameTranslate::Get, IADsNameTranslate::InitEx, IADsNameTranslate::Set, ADS_NAME_TYPE_ENUM