Why is C++ WMI Not Fetching Data? Error: 0xC0000005

0

I'm quite new to WMI, I'm following this guide here.

So I pasted that code in the guide and ran it without any issues using the provided query. But when I changed the query to SELECT State FROM Win32_Service I get no data, just the error code 0xC0000005, which I believe is a permissions error?

That same query above works just fine in the PowerShell using the following command:

Get-WmiObject -Query "select State from Win32_Service"

What I've tried

  • winrm quickconfig

So what gives? Why am I having trouble querying the WMI from my C++ code?

EDIT: I found the line that's causing the crash. I'm not sure why it's crashing though.

wcout << vtProp.bstrVal << endl;
c++
powershell
permissions
wmi
asked on Stack Overflow Jan 21, 2021 by ctrl_alt_del • edited Jan 21, 2021 by ctrl_alt_del

1 Answer

0

I missed this line of code

hr = pclsObj->Get(L"State", 0, &vtProp, 0, 0);

Change the first argument to the property whose value you'd like to retrieve.

answered on Stack Overflow Jan 21, 2021 by ctrl_alt_del

User contributions licensed under CC BY-SA 3.0