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 current user. To initialize the object with a different user credential, use IADsNameTranslate::InitEx.
HRESULT Init( long lnInitType, BSTR bstrADsPath );
Return Code | Description |
---|---|
S_OK | Initialization is successful. |
E_FAIL | Initialization has failed. |
E_ADS_BAD_PARAMETER | lnInitType is invalid. |
HRESULT_FROM_WIN32(ERROR_GEN_FAILURE) | An unspecified error occurred. |
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 example 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, CComBSTR("myServer")); if (FAILED(hr)) { exit 1;} hr =pNto->Set(ADS_NAME_TYPE_1779, CComBSTR("cn=jeffsmith,cn=users,dc=Fabrikam,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 example 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=jeffsmith, CN=users, DC=Fabrikam 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 example 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=jeffsmith,CN=Users,DC=Fabrikam,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>
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.
IADsNameTranslate, IADsNameTranslate::Get, IADsNameTranslate::InitEx, IADsNameTranslate::Set, ADS_NAME_TYPE_ENUM