Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsNameTranslate::InitEx method initializes a name translate object by binding to a specified directory server, domain, or global catalog, using the specified user credential. To initialize the object without an explicit user credential, use IADsNameTranslate::Init.
The IADsNameTranslate::InitEx method initializes the object by setting the server or domain that the object will point to and supplying a user credential.
HRESULT IADsNameTranslate::InitEx( long lnInitType, BSTR bstrADsPath, BSTR bstrUserID, BSTR bstrDomain, BSTR bstrPassword );
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 directory objects. For more information see IADsNameTranslate::Set, IADsNameTranslate::Get, IADsNameTranslate::SetEx, or IADsNameTranslate::GetEx.
The following C/C++ code snippet uses the IADsNameTranslate::InitEx 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->InitEx(ADS_NAME_INITTYPE_SERVER, L"myServer" L"jsmith" L"Microsoft" L"top secret"); 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::InitEx 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" server = "myServer" domain = "Microsoft" user = "jsmith" passwd = "myPass" nto.InitEx ADS_NAME_INITTYPE_SERVER, server,user,domain,passwd nto.Set ADS_NAME_TYPE_1779, dso trans = nto.Get(ADS_NAME_TYPE_NT4) MsgBox "Name in the translated format: " & trans
The following VBScript/ASP code snippet uses the IADsNameTranslate::InitEx 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 server = "myServer" domain = "Microsoft" user = "jsmith" passwd = "myPass" dn = "CN=jsmith,CN=Users,DC=Microsoft,DC=COM" Set nto = Server.CreateObject("NameTranslate") nto.InitEx ADS_NAME_INITTYPE_SERVER, server,user,domain,passwd 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::GetEx, IADsNameTranslate::Set, IADsNameTranslate::SetEx, ADS_NAME_TYPE_ENUM