注意
從 Windows Server 2008 開始,因特網驗證服務 (IAS) 已重新命名為網路原則伺服器 (NPS)。 本主題的內容同時適用於 IAS 和 NPS。 在整個文字中,NPS 會用來參考服務的所有版本,包括原本稱為 IAS 的版本。
下列程式代碼會列舉 NPS 通訊協定集合中的通訊協定。
HRESULT hr;
//
// Retrieve the protocols collection object
//
_variant_t vtIASProtocolsCollection;
hr = pSdo->GetProperty(
PROPERTY_IAS_PROTOCOLS_COLLECTION,
&vtIASProtocolsCollection
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the ISdoCollection interface
// for the object.
//
CComPtr<ISdoCollection> pIASProtocolsCollection;
hr = vtIASProtocolsCollection.pdispVal->QueryInterface(
__uuidof(ISdoCollection),
(void **) &pIASProtocolsCollection
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the enumeration interface, IEnumVARIANT
//
CComPtr<IUnknown> pUnknownProtocol;
hr = pIASProtocolsCollection->get__NewEnum(&pUnknownProtocol);
if (FAILED(hr))
{
return hr;
}
CComPtr<IEnumVARIANT> pEnumProtocols;
hr = pUnknownProtocol->QueryInterface(
__uuidof(IEnumVARIANT),
(void **) &pEnumProtocols
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the first protocol from the collection
//
DWORD dwRetrieved = 1;
_variant_t vtProtocol;
hr = pEnumProtocols->Next(1, &vtProtocol, &dwRetrieved);
if (FAILED(hr))
{
return hr;
}
while (hr != S_FALSE) {
//
// Retrieve the name of the protocol
//
CComPtr<ISdo> pLocalSdo;
hr = vtProtocol.pdispVal->QueryInterface(
__uuidof(ISdo),
(void**)&pLocalSdo
);
if (FAILED(hr))
{
return hr;
}
_variant_t vtName;
hr = pLocalSdo->GetProperty(PROPERTY_SDO_NAME, &vtName);
if (FAILED(hr))
{
return hr;
}
vtProtocol.Clear();
vtName.Clear();
//
// Retrieve the next protocol from the collection
//
dwRetrieved = 1;
hr = pEnumProtocols->Next(1, &vtProtocol, &dwRetrieved);
if (FAILED(hr))
{
return hr;
}
}
備註
vtName 和 vtProtocol 變數的類型為 _variant_t。 _variant_t 物件會封裝或括住 VARIANT 數據類型。 類別會管理資源配置和解除分配,並視需要對 VariantInit 和 VariantClear 進行函式呼叫。
相關主題