title: Using Win32_Process.GetOwner in C++
body: <p>I'm trying to use the WMI class Win32_Process to get a list of running processes and the users who are the owners of each process. The enumeration of processes using Win32_Process in C++ wasn't that difficult using the enumeration example from MSDN (<a href="https://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx" rel="nofollow noreferrer">MSDN</a>) and simply changing Win32_OperatingSystem to Win32_Process. I have found that by using the GetOwner method of Win32_Process I can get the user and domain of the owner of a process. There is a great example of this in VB (<a href="https://msdn.microsoft.com/en-us/library/aa390460(v=vs.85).aspx" rel="nofollow noreferrer">MSDN</a>) which shows that I can use the enumerator object to call the specific instance of GetOwner for the process information at any given point in the enumeration. </p>
  
  <p>I have attempted to use the code example (<a href="https://msdn.microsoft.com/en-us/library/aa390421(v=vs.85).aspx" rel="nofollow noreferrer">MSDN</a>) for "Calling a Provider Method" to figure out how to make the method call to GetOwner but I cannot figure out how to get it to work. I am continually hitting road blocks. typically I get the invalid method parameters. Take the following code chunk</p>
  
  <pre><code>        BSTR MethodName = SysAllocString(L"GetOwner");
          BSTR ClassName = SysAllocString(L"Win32_Process");
  
          IWbemClassObject* pClass = NULL;
          hres = pSvc-&gt;GetObject(ClassName, 0, NULL, &amp;pClass, NULL);
          printf("[1] hres = %08x\n", hres);
  
          IWbemClassObject* pInParamsDefinition = NULL;
          IWbemClassObject* pOutParams = NULL;
          hres = pClass-&gt;GetMethod(MethodName, 0, &amp;pInParamsDefinition, &amp;pOutParams);
          printf("[2] hres = %08x (%08x, %08x)\n", hres, pInParamsDefinition, pOutParams);
  
          // Execute Method
          hres = pSvc-&gt;ExecMethod(L"Win32_Process", MethodName, 0, NULL, NULL, &amp;pOutParams, NULL);
  
          VARIANT varReturnValue;
          hres = pOutParams-&gt;Get(_bstr_t(L"ReturnValue"), 0,
              &amp;varReturnValue, NULL, 0);
          wprintf(L"The command is: %s\n", V_BSTR(&amp;varReturnValue));
  </code></pre>
  
  <p>GetOwner has not input parameters and when I call GetMethod the pInParamsDefinition always returns NULL while pOutParams returns a ptr. Since there isn't a pointer returned to pInParamsDefinition, I can't supply inputs and as such I don't know how to get around the invalid method parameters issue. Clearly WMI programming isn't my strongest skill :) </p>
  
  <p>What am I missing here?</p>