IADsPathname, interfejs
Interfejs IADsPathname analizuje i modyfikuje różne elementy ścieżki ADsPath. Konwertuje również ścieżki ADsPath między różnymi formatami wyświetlania.
Poniższy przykład kodu wyodrębnia i zwraca nazwę serwera z prawidłowej ścieżki ADsPath do wyświetlania użytkownikowi w narzędziu obsługi.
HRESULT GetServerName(BSTR adsPath, BSTR *adsServer)
{
HRESULT hr = S_OK;
IADsPathname *pIADsPathname = NULL;
// Create the IADsPathname object.
hr = CoCreateInstance(CLSID_Pathname,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsPathname,
(void**) &pIADsPathname);
if (FAILED(hr))
{
if (pIADsPathname)
pIADsPathname->Release();
return (hr);
}
// Set the path.
hr = pIADsPathname->Set(adsPath, ADS_SETTYPE_FULL);
if (SUCCEEDED(hr))
// Extract and return the server name.
hr = pIADsPathname->Retrieve(ADS_FORMAT_SERVER, adsServer);
// Cleanup.
pIADsPathname->Release();
return (hr);
}
Poniższy przykład kodu pomaga zainicjować nowo utworzony obiekt ADSI, ustawiając właściwość Nazwa wyróżniająca obiektu z własnej ścieżki ADsPath. Należy pamiętać, że procedury wywoływania muszą zatwierdzać wszelkie zmiany w bazowym magazynie katalogów, wywołując metodę SetInfo.
HRESULT SetDistinguishedName(IADs *pIADs)
{
HRESULT hr = S_OK;
CComBSTR sbstrADsPath;
IADsPathname *pIADsPathname = NULL;
// Get the ADsPath for this object.
hr = pIADs->get_ADsPath(&sbstrADsPath);
if (FAILED(hr))
return (hr);
// Create the IADsPathname object.
hr = CoCreateInstance(CLSID_Pathname,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsPathname,
(void**) &pIADsPathname);
if (FAILED(hr))
{
if (pIADsPathname)
pIADsPathname->Release();
return (hr);
}
// Set the path.
hr = pIADsPathname->Set(sbstrADsPath, ADS_SETTYPE_FULL);
if (SUCCEEDED(hr))
{
CComBSTR sbstrDNPath;
// Convert the path to Distinguished Name format.
hr = pIADsPathname->Retrieve(ADS_FORMAT_WINDOWS_DN,
&sbstrDNPath);
if (SUCCEEDED(hr))
{
// Set the distinguished name property.
VARIANT var;
VariantInit(&var);
V_BSTR(&var) = sbstrDNPath;
V_VT(&var) = VT_BSTR;
hr = pIADs->Put(CComBSTR("distinguishedName"), var);
VariantClear(&var);
}
}
// Cleanup.
pIADsPathname->Release();
return (hr);
}