Jump to content

Help in getting System Idle time


Recommended Posts

I have been looking for a utility that when ran will show the time remaining before the system is put into S3/S4 mode (TimeRemaining) as well as the Idleness, to help troubleshoot power management problems. These two pieces of information will help determine why power management (system going to StandBy) isn't working. I wasn't able to find a utility so I am trying to write one and can't seem to get it to work.

I found the PowrProf.dll function http://msdn.microsoft.com/en-us/library/aa372675.aspxCallNtPowerInformation which returns the data structure SYSTEM_POWER_INFORMATION.

I found this post which helped me with my code: http://www.autoitscript.com/forum/index.ph...mode=linearplus

I can get the values OK, however I want the application to continusly (every second) query this data. The problem I cannot figure out is how to re-query the data after the initial call. I can make the call and get the value of the timer, however any other calls to get the data don't work becuase I always get the same value back (the value the initial call got).

What am I doing wrong? Anyone help me with this? In the example below I am just trying to get the Idleness, which is essentialy the amount of the processor not being used.

CODE
#NoTrayIcon

#include <GUIConstantsEx.au3>

GUICreate("My Test", 200, 100)

GUICtrlCreateLabel("TEST: ", 30, 10)

GUISetState(@SW_SHOW)

$Idleness=0

for $n = 1 to 20

GetPowerInformation($Idleness)

GUICtrlCreateLabel("TEST" & $n & ":" & $Idleness, 30, 10)

sleep(1000)

Next

Exit

Func GetPowerInformation(ByRef $A)

;Create structure for SYSTEM_POWER_INFORMATION

$SystemPowerInformation=DllStructCreate("long;long;long;char")

If @Error Then

MsgBox(0,"DllStructureCreate",@Error)

EndIf

;Execute DllCall

$Ret=DllCall("PowrProf.dll","ptr","CallNtPowerInformation","int","12","ptr","0","long","0","ptr",DllStructGetPtr($SystemPowerInformation),"long",DllStructGetSize($SystemPowerInformation))

If @Error Then

MsgBox(0,"DllCall",@Error)

EndIf

$A=DllStructGetData($SystemPowerInformation,2) ;Idleness

$SystemPowerInformation=0

EndFunc

Any help would be appreciated.

Edited by ejmichaud
Link to comment
Share on other sites

Look up _Timer_GetIdleTime() in the help file.

:)

Getting the Idle Time will be of no help here, I need to know the values for TimeRemaining, and Idleness. The reason being is that even when the system is idle, the TimeRemaining can be re-set by applications or when processor utilization is above the maximum threshold configured for that system. The Idle Time will continue to increase, however the TimeRemaining can get reset which is the timer the system uses to determine when to go to sleep. This is why I am specifically looking for a way to get the TimeRemaining and the Idleness values.

Link to comment
Share on other sites

Getting the Idle Time will be of no help here, I need to know the values for TimeRemaining, and Idleness. The reason being is that even when the system is idle, the TimeRemaining can be re-set by applications or when processor utilization is above the maximum threshold configured for that system. The Idle Time will continue to increase, however the TimeRemaining can get reset which is the timer the system uses to determine when to go to sleep. This is why I am specifically looking for a way to get the TimeRemaining and the Idleness values.

Hmm...

I get data back this way:

#include <GUIConstantsEx.au3>

Global $Idleness = 0

For $n = 1 To 20
    GetPowerInformation($Idleness)
    ConsoleWrite("TEST " & $n & ":  " & $Idleness & @LF & @LF)
    Sleep(1000)
Next

Func GetPowerInformation(ByRef $A)
;Create structure for SYSTEM_POWER_INFORMATION
    $SystemPowerInformation = DllStructCreate("long;long;long;char")
    If @error Then
        MsgBox(0, "DllStructureCreate", @error)
    EndIf

;Execute DllCall
    $Ret = DllCall("PowrProf.dll", "ptr", "CallNtPowerInformation", _
            "int", "12", _
            "ptr", "", _
            "long", "0", _
            "ptr", DllStructGetPtr($SystemPowerInformation), _
            "long", DllStructGetSize($SystemPowerInformation))
    If @error Then ConsoleWrite("Debug:  DllCall error:  " & @error & @LF)
    ConsoleWrite("Debug: $Ret[0] = " & $Ret[0] & @LF)
    ConsoleWrite("Debug: ULONG MaxIdlenessAllowed = " & DllStructGetData($SystemPowerInformation, 1) & @LF)
    ConsoleWrite("Debug: ULONG Idleness = " & DllStructGetData($SystemPowerInformation, 2) & @LF)
    ConsoleWrite("Debug: ULONG TimeRemaining = " & DllStructGetData($SystemPowerInformation, 3) & @LF)
    ConsoleWrite("Debug: UCHAR CoolingMode = " & DllStructGetData($SystemPowerInformation, 4) & @LF)

    $A = DllStructGetData($SystemPowerInformation, 2);Idleness
    $SystemPowerInformation = 0
EndFunc  ;==>GetPowerInformation

Idleness = 0 every time, so I wonder if that is thrown off by the AutoIt script running (because it's busy running the script, idle = 0)?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...