将对象添加到集合
以下代码将新策略添加到 IAS 策略集合。 变量 pClientsCollection 指向集合的 ISdoCollection 接口。 有关如何 检索集合 对象的信息,请参阅检索集合。
HRESULT hr;
_bstr_t bstrClientName = L"Test Client";
VARIANT_BOOL vbNameUnique = VARIANT_FALSE;
//
// Check if the new client's name is unique
//
hr = pClientsCollection->IsNameUnique(bstrClientName, &vbNameUnique);
if (FAILED(hr))
{
return hr;
}
if (VARIANT_FALSE == vbNameUnique)
{
//
// The name is not unique. Handle the error
//
return E_FAIL;
}
//
// Name is unique. Add the client.
//
CComPtr<IDispatch> pClientDispatch;
pClientDispatch.p = NULL;
hr = pClientsCollection->Add(bstrClientName, &pClientDispatch);
if (FAILED(hr))
{
return hr;
}
CComPtr<ISdo> pClientSDO;
hr = pClientDispatch->QueryInterface(
__uuidof(ISdo),
(void**) &pClientSDO
);
if (FAILED(hr))
{
return hr;
}
//
// Set the address for the client
//
_variant_t vtClientAddress = L"127.0.0.1";
hr = pClientSDO->PutProperty(PROPERTY_CLIENT_ADDRESS, &vtClientAddress);
if (FAILED(hr))
{
return hr;
}
//
// Set the shared secret for the client
//
_variant_t vtClientSecret = L">@U#'6cc='5Ly9O5QKEj2RTJr*fM";
hr = pClientSDO->PutProperty(PROPERTY_CLIENT_SHARED_SECRET, &vtClientSecret);
if (FAILED(hr))
{
return hr;
}
//
// Apply the changes
//
hr = pClientSDO->Apply();
if (FAILED(hr))
{
return hr;
}
//
// Refresh the service using a ISdoServiceControl interface retrieved
// in the code sample "Retrieve a Service SDO"
//
hr = pSdoServiceControl->ResetService();
if (FAILED(hr))
{
//
// If IAS is not installed or is not running then ignore the error
//
}
相关主题