Detect power mode
- RandomGgames
- Posts: 6
- Joined: 28 Mar 2017, 07:12
- Location: USA
- Contact:
Detect power mode
Is there a way to detect the current power mode selected on your PC? For instance... you have a High performance and a Low Power mode for your laptop and I want to be able to read what is currently selected and read it as a variable so I can execute something else if High Power is active or if Low Power is.
-Random
Re: Detect power mode
Assuming you're talking about Windows' power profiles feature and not something specific to whatever laptop you use, you can do something like to get the name of the currently active profile name:
Code: Select all
if (DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", pguid) == 0) {
VarSetCapacity(desc, (szdesc := 256) + 2)
if (DllCall("powrprof\PowerReadFriendlyName", "Ptr", 0, "Ptr", pguid, "Ptr", 0, "Ptr", 0, "Ptr", &desc, "UInt*", szdesc) == 0, DllCall("LocalFree", "Ptr", pguid, "Ptr")) {
activeProfileName := StrGet(&desc, "UTF-16")
MsgBox % activeProfileName
}
}
- RandomGgames
- Posts: 6
- Joined: 28 Mar 2017, 07:12
- Location: USA
- Contact:
Re: Detect power mode
I actually figured out how to do it through the registry by rereading the current profile (which gives me the ID), and I use that variable to read the friendly name of the ID
Code: Select all
RegRead, CurrentPowerMode, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes, ActivePowerScheme
RegRead, CurrentPowerModeName, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\%CurrentPowerMode%, FriendlyName
MsgBox, 0, Test, %CurrentPowerModeName%
-Random
Re: Detect power mode
Since it seems you are into the Pwrproff.dll. can you give me a quick helpqwerty12 wrote:Assuming you're talking about Windows' power profiles feature and not something specific to whatever laptop you use, you can do something like to get the name of the currently active profile name:
Code: Select all
if (DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", pguid) == 0) { VarSetCapacity(desc, (szdesc := 256) + 2) if (DllCall("powrprof\PowerReadFriendlyName", "Ptr", 0, "Ptr", pguid, "Ptr", 0, "Ptr", 0, "Ptr", &desc, "UInt*", szdesc) == 0, DllCall("LocalFree", "Ptr", pguid, "Ptr")) { activeProfileName := StrGet(&desc, "UTF-16") MsgBox % activeProfileName } }
I wish to read this settings from the current powerprofile (bolded)
Subgroup GUID: 54533251-82be-4824-96c1-47b60b740d00 (Processor power management)
GUID Alias: SUB_PROCESSOR
Power Setting GUID: 0cc5b647-c1df-4637-891a-dec35c318583 (Processor performance core parking min cores)
GUID Alias: CPMINCORES
Minimum Possible Setting: 0x00000000
Maximum Possible Setting: 0x00000064
Possible Settings increment: 0x00000001
Possible Settings units: %
Current AC Power Setting Index: 0x00000064
Current DC Power Setting Index: 0x00000005
Perhaps even change it
Re: Detect power mode
You can try something like this:SvenBent wrote: I wish to read this settings from the current powerprofile (bolded)
Code: Select all
GetCoreParkingMinCoresAcSettingForCurrentPowerProfile()
{
static cbguid := 16, CLSIDFromString := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "ole32.dll", "Ptr"), "AStr", "CLSIDFromString", "Ptr")
,guids := {"GUID_PROCESSOR_SETTINGS_SUBGROUP": "{54533251-82be-4824-96c1-47b60b740d00}"
, "GUID_PROCESSOR_CORE_PARKING_MIN_CORES": "{0cc5b647-c1df-4637-891a-dec35c318583}"}
if (guids.GetCapacity("GUID_PROCESSOR_SETTINGS_SUBGROUP") != cbguid) {
for k, v in guids {
guids.SetCapacity(k, cbguid)
,DllCall(CLSIDFromString, "WStr", v, "Ptr", guids.GetAddress(k))
}
}
if (DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", pguid) == 0) {
if (DllCall("powrprof\PowerReadACValueIndex", "Ptr", 0, "Ptr", pguid, "Ptr", guids.GetAddress("GUID_PROCESSOR_SETTINGS_SUBGROUP"), "Ptr", guids.GetAddress("GUID_PROCESSOR_CORE_PARKING_MIN_CORES"), "UInt*", acCoreParkingMincores, "UInt") == 0) {
MsgBox % acCoreParkingMincores
}
; writing:
; DllCall("powrprof\PowerWriteACValueIndex", "Ptr", 0, "Ptr", pguid, "Ptr", guids.GetAddress("GUID_PROCESSOR_SETTINGS_SUBGROUP"), "Ptr", guids.GetAddress("GUID_PROCESSOR_CORE_PARKING_MIN_CORES"), "UInt", 80, "UInt")
DllCall("LocalFree", "Ptr", pguid, "Ptr")
}
}
Re: Detect power mode
[quote="qwerty12"][/quote]
Thank you. that hellped a lot. i modified your code to my own written style and made a few adjustment. but the code works perfect.
I'm still having hard time in general with datastructures and dll calls
A funny part about this is that this read the settings from powerprofile and not the live settings
If i change a power profile but dot not activate it, so the changes are not live.
This code will show the changes even though its not active yet.
not a problem for me just a random facts to share
Thank you. that hellped a lot. i modified your code to my own written style and made a few adjustment. but the code works perfect.
I'm still having hard time in general with datastructures and dll calls
A funny part about this is that this read the settings from powerprofile and not the live settings
If i change a power profile but dot not activate it, so the changes are not live.
This code will show the changes even though its not active yet.
not a problem for me just a random facts to share
Re: Detect power mode
Oh, sorry, I know you have to reactivate the current profile if you change the brightness but it completely slipped my mind that doing it for effecting other changes might be necessary.SvenBent wrote: If i change a power profile but dot not activate it, so the changes are not live.
This code will show the changes even though its not active yet.
not a problem for me just a random facts to share
You can add DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", pguid, "UInt") before the DllCall to LocalFree if you want the system to reactivate (and take in the changes of) the currently active profile
Re: Detect power mode
Thank you but its already works perfect for my purpose.qwerty12 wrote:Oh, sorry, I know you have to reactivate the current profile if you change the brightness but it completely slipped my mind that doing it for effecting other changes might be necessary.SvenBent wrote: If i change a power profile but dot not activate it, so the changes are not live.
This code will show the changes even though its not active yet.
not a problem for me just a random facts to share
You can add DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", pguid, "UInt") before the DllCall to LocalFree if you want the system to reactivate (and take in the changes of) the currently active profile
what i do now is i reade the states of the profile.
change the state in the profile
reactive the profile
Change the state back to the old value.
This way there is no permanetn change in the users profile and a reboot/restart is always back to normal
Who is online
Users browsing this forum: Google [Bot] and 240 guests