IWbemClassObject获取成功,而Put with Error:ERROR_SXS_KEY_NOT_FOUND 140007

时间:2011-12-13 03:33:21

标签: c++ wmi

代码的主要目标是自定义虚拟内存页面文件的InitialSize和MaximumSize。

ENV:Windows Server 2008

代码:

...
...
IWbemClassObject* pclsObj = NULL;
ULONG uReturn = 0;

while(pEnumerator)
{
    HRESULT hr = pEnumerator->Next(WBEM_INFINITE,1, &pclsObj, &uReturn);
    VARIANT initial_size;
    VARIANT maximum_size;


    //InitialSize 
    pclsObj->Get(L"InitialSize", 0, &initial_size, 0, 0);

    //get the maximumsize of the pagefile
    //MaximumSize  
    pclsObj->Get(L"MaximumSize", 0, &maximum_size, 0, 0); //successfully


    //use the put to adjust the pagefile size

    VARIANT in_initialsize;
    VariantInit(&in_initialsize);
    in_initialsize.vt = VT_I4;
    in_initialsize.iVal = 13000;

    //set the initialsize of the pagefile
    hr = pclsObj->Put(L"InitialSize", 0, &in_initialsize, 0); //failed with 14007
        ...
        ...
}
...

谢谢

1 个答案:

答案 0 :(得分:0)

使用其他解决方案,最后获取实例GetObject。必须执行Put操作;如下所示:

...
l_pSVC->PutInstance(l_pinObj, WBEM_FLAG_UPDATE_ONLY, NULL, NULL);
...