Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Retrieves the cluster-wide environment variables. The variables are available to all tasks on all nodes.
Syntax
HRESULT get_EnvironmentVariables(
[out] INameValueCollection **pRetVal
);
Parameters
- pRetVal [out]
An INameValueCollection interface that contains the collection of environment variables. The variant type of each item in the collection is VT_DISPATCH. Query the pdispVal member of the variant for the INameValue interface.
Return value
If the method succeeds, the return value is S_OK. Otherwise, the return value is an error code. To get a description of the error, call the ICluster::get_ErrorMessage method.
Remarks
To set a cluster-wide environment variable, call the ICluster::SetEnvironmentVariable method. To set an environment variable that is available to a specific task, call the ITask::SetEnvironmentVariable method.
Examples
The following example shows how to call this method. The example assumes the pCluster parameter points to a valid ICluster interface.
void ListClusterEnvironmentVariables(ICluster* pCluster)
{
HRESULT hr = S_OK;
INameValueCollection* pCollection = NULL;
INameValue* pVariable = NULL;
IEnumVARIANT* pVariables = NULL;
long count = 0;
BSTR bstrClusterName = NULL;
BSTR bstrVariableName = NULL;
BSTR bstrVariableValue = NULL;
VARIANT var;
hr = pCluster->get_EnvironmentVariables(&pCollection);
if (FAILED(hr))
{
wprintf(L"pCluster->get_EnvironmentVariables failed.\n");
return;
}
hr = pCollection->GetEnumerator(&pVariables);
if (FAILED(hr))
{
wprintf(L"pCollection->GetEnumerator failed.\n");
goto cleanup;
}
hr = pCollection->get_Count(&count);
if (FAILED(hr))
{
wprintf(L"pCollection->get_Count failed.\n");
goto cleanup;
}
hr = pCluster->get_Name(&bstrClusterName);
if (FAILED(hr))
{
wprintf(L"pCluster->get_Name failed.\n");
goto cleanup;
}
wprintf(L"\nThe following lists the %d environment variable for the cluster, %s:\n", count, bstrClusterName);
VariantInit(&var);
while (hr = pVariables->Next(1, &var, NULL) == S_OK)
{
var.pdispVal->QueryInterface(IID_INameValue, reinterpret_cast<void **> (&pVariable));
hr = pVariable->get_Name(&bstrVariableName);
if (SUCCEEDED(hr))
{
wprintf(L"\nName: %s\n", bstrVariableName);
SysFreeString(bstrVariableName);
hr = pVariable->get_Value(&bstrVariableValue);
if (SUCCEEDED(hr))
{
wprintf(L"Value: %s\n", bstrVariableValue);
SysFreeString(bstrVariableValue);
}
else
{
wprintf(L"Failed to get variable value.\n");
}
}
else
{
wprintf(L"Failed to get variable name.\n");
}
pVariable->Release();
pVariable = NULL;
VariantClear(&var);
}
cleanup:
if (pCollection)
pCollection->Release();
if (pVariables)
pVariables->Release();
SysFreeString(bstrClusterName);
return;
}
Requirements
Product |
Compute Cluster Pack Client Utilities |
Type library |
Ccpapi.tlb |