Question

I'm having trouble with the following code:

import wmi
c = wmi.WMI()
for plan in c.Win32_PowerPlan():
    print plan

It returns AttributeError: winmgmts:.Win32_PowerPlan where it should return all the power plan instances on the machine. What am I getting wrong?

Was it helpful?

Solution

The problem here is that the Win32_PowerPlan class is not a direct Win32 class in the \root\CIMV2 namespace, which is why it's not in this list of Win32 classes in the documentation.

It actually resides in the \\.\root\CIMV2\power namespace as can be found by scrolling down to the table at the bottom of the Win32_PowerPlan class documentation.

The code required to access this makes use of the moniker parameter of the WMI() class as follows:

c = wmi.WMI(moniker = "//./root/cimv2/power")
for plan in c.Win32_PowerPlan():
    print plan
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top