Tuesday, 2 August 2016

Getting the value of a setting in the power plan

Here is another one that was a pain!

First of all I was led down the garden path of attempting to do this through the use of C++ libraries:

This had its own problems of attempting to convert items to and from IntPtr in order to leverage the PowerEnumerate method within powerprof.dll.

Luckily while googling something else I came across the WMI classes of "Win32_PowerSetting" and "Win32_PowerPlan".

I needed to get the current value for the sleep timeout. The first thing to do is check the currently active power plan, and then get all the settings from different plans that match the GUID for the sleep timeout.

Once that is retrieved as a collection, I check which one is the one used by the currently active plan, and then read and return the value. See below:



No comments:

Post a Comment