VC++ call wmi case WmiPrvSE.exe high memory footprint.

Fusong Li 1 Reputation point
2021-03-19T09:26:17.067+00:00

Dear sir.
help please, win10 x64 and vs2017
below code will case the process WmiPrvSE.exe high memory footprint.

    HRESULT hres;
    IWbemClassObject* pInParamsDefinition = NULL;        
    IWbemClassObject* pClassInstance = NULL; 
    IWbemClassObject* pInClassParamsDefinition = NULL; 
    IWbemClassObject* pInClassInstance = NULL; 
    IWbemClassObject* pOutClass = NULL;   
    _bstr_t szMethodName=L"Your Method Name";
    WCHAR sInClassName[]=L"Your Class Name";
    VARIANT var;
    PVOID pVoid;

     // detect hres value not post to here
    hres = pClass->GetMethod(szMethodName, 0, &pInParamsDefinition, NULL);
    hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance); 
    SAFE_RELEASE_OBJECT(pInParamsDefinition);// Don't need the class any more

    hres = pSvc->GetObject(sInClassName, 0, NULL, &pInClassParamsDefinition, NULL);
    hres = pInClassParamsDefinition->SpawnInstance(0,&pInClassInstance);
    SAFE_RELEASE_OBJECT(pInClassParamsDefinition);// Don't need the class any more

    VariantInit(&var);
    V_VT(&var)=VT_I4;
    V_I4(&var)=1234;
    pInClassInstance->Put(L"Value0",0,&var,0);
    VariantClear(&var);

    V_VT(&var) = VT_I4;
    V_I4(&var)=2345;
    pInClassInstance->Put(L"Value1",0,&var,0);
    VariantClear(&var);

    V_VT(&var)=VT_UNKNOWN;
    pInClassInstance->QueryInterface(IID_IUnknown, (PVOID*)&V_UNKNOWN(&var));
    pClassInstance->Put(L"Pack",0,&var,0);
    SAFE_RELEASE_OBJECT(pInClassInstance);
    VariantClear(&var);

    // Execute Method
    hres = pSvc->ExecMethod(varPath.bstrVal, szMethodName,0,NULL, pClassInstance,&pOutClass,NULL);
    if (SUCCEEDED(hres)&&pOutClass!=NULL) 
    {
        pOutClass->Get(L"status",0,&var,0,0);
        pWMI_VALUE->status=V_UI4(&var);
        VariantClear(&var);
    }
    else
    {

    }

FUNCTIONEXIT_:
    SAFE_RELEASE_OBJECT(pOutClass);
    SAFE_RELEASE_OBJECT(pClassInstance);
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,429 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Strive Sun-MSFT 426 Reputation points
    2021-03-22T09:46:21.063+00:00

    Hello, @Fusong Li

    Please check: High CPU usage by the WMI Provider Host (WmiPrvSE.exe) process at regular intervals in Windows

    This article provides a workaround for the issue of high CPU usage by WmiPrvSE.exe process at regular intervals.

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.