-
Notifications
You must be signed in to change notification settings - Fork 5
Description
The Issue I've noticed with Windows is that depending on how laptop vendors implement their firmware, Different GUID's might not be available to choose from.
For example, on my Framework 16 Laptop:

Only these options are available [and not "Better Performance"]
Which Is why I'm happy to report that I figured out how to make the PowerGetOverlaySchemes API work correctly!
/// <summary>
/// Retrieves a list of available power overlay schemes and their count.
/// </summary>
/// <param name="overlaySchemes">A pointer to a list of GUID structures. [The caller must free this memory]</param>
/// <param name="schemeCount">The number of GUID overlay schemes retrieved.</param>
/// <param name="filter">A filter or control flag. [Seems to have no effect]</param>
/// <returns>Returns zero if the call was successful, and a nonzero value if the call failed.</returns>
[DllImport("powrprof.dll", EntryPoint = "PowerGetOverlaySchemes", SetLastError = true)]
private static extern uint PowerGetOverlaySchemes(
out IntPtr overlaySchemes,
out int schemeCount,
byte filter
);And then, for using it:
IntPtr overlaySchemes;
int schemeCount;
byte filter = 0; // Example filter value
result = PowerGetOverlaySchemes(out overlaySchemes, out schemeCount, filter);
if (result == 0) // Assuming 0 is success
{
Console.WriteLine($"Retrieved {schemeCount} overlay schemes.");
// Process the schemes (assuming GUIDs are stored, 16 bytes each)
for (int i = 0; i < schemeCount; i++)
{
IntPtr schemePtr = IntPtr.Add(overlaySchemes, i * 16);
Guid scheme = Marshal.PtrToStructure<Guid>(schemePtr);
Console.WriteLine($"Scheme {i + 1}: {scheme}");
}
// Free allocated memory
Marshal.FreeHGlobal(overlaySchemes);
}
else
{
Console.WriteLine($"Failed to retrieve overlay schemes. Error code: {result}");
}This outputs the GUID's for
"961cc777-2547-4f9d-8174-7d86181b8a7a" [Better Battery]
"ded574b5-45a0-4f42-8737-46345c09c238" [Best Performance]
Seems like it doesn't output the GUID for "Balanced", as it might be the default value that should always be available based on the fact that it's GUID is "00000000-0000-0000-0000-000000000000"
Feel free to try this out on your laptops, and report your findings!
