[DllImport("powrprof.dll", SetLastError=true)]
static extern uint PowerEnumerate(IntPtr RootPowerKey,
IntPtr SchemeGuid,
IntPtr SubGroupOfPowerSettingsGuid,
PowerDataAccessor AccessFlags,
uint Index,
IntPtr Buffer,
ref uint BufferSize);
enum PowerDataAccessor : uint
{
ACCESS_AC_POWER_SETTING_INDEX = 0,
ACCESS_DC_POWER_SETTING_INDEX = 1,
ACCESS_SCHEME = 16,
ACCESS_SUBGROUP = 17,
ACCESS_INDIVIDUAL_SETTING = 18,
ACCESS_ACTIVE_SCHEME = 19,
ACCESS_CREATE_SCHEME = 20
}
Declare Function PowerEnumerate Lib "powrprof.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
Use EnumPwrSchemes for Windows versions prior to Vista.
Please add some!
List<Guid> GUIDs = new List<Guid>();
IntPtr ReadBuffer;
uint BufferSize = 16;
uint Index = 0;
uint ReturnCode = 0;
while (ReturnCode == 0)
{
ReadBuffer = Marshal.AllocHGlobal((int)BufferSize);
try
{
ReturnCode = PowerEnumerate(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, PowerDataAccessor.ACCESS_SCHEME, Index, ReadBuffer, ref BufferSize);
if (ReturnCode == 259) break; // no more data
if (ReturnCode != 0)
{
throw new COMException("Error occurred while enumerating power schemes. Win32 error code: " + ReturnCode);
}
Guid NewGuid = (Guid) Marshal.PtrToStructure(ReadBuffer, typeof(Guid));
GUIDs.Add(NewGuid);
}
finally
{
Marshal.FreeHGlobal(ReadBuffer);
}
Index++;
}
// now we have a list of identifiers for all the power schemes on the system,
// we can pass those into other powrprof methods to retrieve more information on each