Sign in to follow this  
Followers 0

Control windows power plan through idle

1 post in this topic

#1 ·  Posted (edited)

#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 :
    $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
     if $temp > 50 Then                            ; normal cpu temp from 40 to 60°C ; idle 35 to 40°C
        $Limit = 1
        $Limit = 10
EndFunc   ;==>findTemp

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

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

Func _Quit()
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%


Edited by Wiffzack

Share this post

Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me
    • breakbadsp
      By breakbadsp
      AutoIT AU3info doeas not detect all gui objects uniquely for .NET GUIs developed in C#.
      this is not working now i am using COM windows approach for this, But its very difficult.
      Please let me know if anyone has done it before.
    • ur
      By ur
      With _WinWaitActivate we can wait for a window to process it.
      But is there any logic so that we can wait for this window title and based on the window text (like 2 or more patterns will be there) we can click yes or no on the window.
      Func _WinWaitActivate($title,$text,$timeout=0)
       If Not WinActive($title,$text) Then WinActivate($title,$text)
    • wtarkan
      By wtarkan
      If I create a service to run a program , Application window cannot Appear - How can I make the App window visible
    • ur
      By ur
      Whenever we try to access a network share it will prompt for credentials based on the shared folder settings.
      Like the below prompt

      Once you save them, they are saved in Windows Credentials of Credentials Manager in Control panel (run --> control keymgr.dll).

      But not able to found exact file or registry for this setting.
      So, can anyone suggest how to do this process of adding network credentials using AutoIT.