question

FusongLi-4981 avatar image
0 Votes"
FusongLi-4981 asked FusongLi-1170 published

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

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-apic++
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


What is the purpose of your code?

0 Votes 0 ·

my app will call wmi method, we found the code as the post, will case the windows process WmiPrvSE.exe high memory footprint
after one day , the process WmiPrvSE.exe , memory use over 200MB

0 Votes 0 ·

Does it happen with any WMI class and method?

0 Votes 0 ·
Show more comments

1 Answer

StriveSun-MSFT avatar image
1 Vote"
StriveSun-MSFT answered FusongLi-1170 published

Hello, @FusongLi-4981

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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi , thanks for your reply
My problem is that the memory occupied by the WmiPrvSE.exe process will gradually increase, and the memory occupied by the process will become larger and larger over time, and the CPU occupied by this process is very small (less than 1%)

If the put function of the class IWbemClassObject, the parameter pVal includes a member of VT_UNKNOWN, it can be copied to this problem.
Such as the following code, if you comment it out, you will not see this phenomenon


  pClassInstance->Put(L"Pack",0,&var,0); // if mark this line, will not see the issue

or commit out below code, won't see this phenomenon

  V_VT(&var)=VT_UNKNOWN;
  pInClassInstance->QueryInterface(IID_IUnknown, (PVOID*)&V_UNKNOWN(&var));
0 Votes 0 ·

I am looking into this question, any update will post here.

0 Votes 0 ·

sir.
do you have any good suggestions? thanks

0 Votes 0 ·

sir.
do you have any new message ?

0 Votes 0 ·