Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

PowerEnumerate (powrprof)
 
.
Summary
Enumerates the specified elements in a power scheme. This function is normally called in a loop incrementing the Index parameter to retrieve subkeys until they've all been enumerated.

C# Signature:

[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
}

VB Signature:

Declare Function PowerEnumerate Lib "powrprof.dll" (RootPowerKey As IntPtr,
                SchemeGuid As IntPtr,
                SubGroupOfPowerSettingsGuid As IntPtr,
                AccessFlags As PowerDataAccessor,
                Index As UInteger,
                Buffer As IntPtr,
                ByRef BufferSize As UInteger) As UInteger

Public Enum PowerDataAccessor As UInteger
     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
End Enum
Declare Function PowerEnumerate Lib "powrprof.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Use EnumPwrSchemes for Windows versions prior to Vista.

Tips & Tricks:

Please add some!

Sample Code:

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

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions