Jump to content

Control windows power plan through idle


Wiffzack
 Share

Recommended Posts

#RequireAdmin
#include <Timers.au3>
#include <GUIConstants.au3>

Global $Limit = 5 ; idle limit in seconds
Global $objWMIService;
Global $Instances;
Global $temp;
Local  $Counter = 0

HotKeySet("{ESC}", "_Quit")

AdlibRegister("_CheckIdleTime", 500)   ; default 250ms
AdlibRegister("_findTemp", 60000)      ; default 250ms  ; 

; Not all system support this function!!!
Func findTemp()                                     ;;; Source : http://stackoverflow.com/questions/25139311/autoit-get-cpu-temp-and-put-it-into-a-graph
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
    $Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
    For $Item In $Instances
        $temp = ($Item.CurrentTemperature - 2732) / 10 ; set the temp
     Next
     if $temp > 50 Then                            ; normal cpu temp from 40 to 60°C ; idle 35 to 40°C
        $Limit = 1
     Else
        $Limit = 10
      EndIf
EndFunc   ;==>findTemp

While 1
    Sleep(20)
    if($Counter == 0) Then
       Run("C:\Windows\System32\cmd.exe", "", @SW_HIDE)
       $Counter = 1
       EndIf
WEnd

Func _CheckIdleTime()
    If (_Timer_GetIdleTime() > $Limit * 1000) Then
       ProcessWait("cmd.exe")
       Local $hwnd = WinGetHandle("[REGEXPTITLE:(?i)(.*cmd.*|.*cmd.*)]")
       ControlSend($hwnd, "", "", "powercfg -setactive a1841308-3541-4fab-bc81-f71556f20b4a{Enter}")
    else
       ProcessWait("cmd.exe")
       Local $hwnd = WinGetHandle("[REGEXPTITLE:(?i)(.*cmd.*|.*cmd.*)]")
       ControlSend($hwnd, "", "", "powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e{Enter}")
    EndIf
EndFunc   ;==>_CheckIdleTime

Func _Quit()
    Exit
EndFunc   ;==>_Quit

The first attempt !!!, to control the power plan through idle. This script should adjust the power plan to the individual situation. This is to slow down the overheat. 

findTemp() function will only run on supported systems!

This batch script shows you whether your system support this function:

If the script does not work,  meaningless values are outputted.

@echo off
for /f "delims== tokens=2" %%a in (
    'wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value'
) do (
    set /a degrees_celsius=%%a / 10 - 273
)
echo %degrees_celsius%
pause

 

Edited by Wiffzack
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...