Jump to content

How to detect the pc was recently reactivated from StandBy


Romanz
 Share

Recommended Posts

AutoIt 3.3.10.1 with Windows 7 64bit

hi all,

i run my scripts automated by the windows tasks scheduler.

the computer is on StandBy, wakes up and start the script.

I only want to run the script if the computer was on StandBy some minutes before.

At the windows system log i can find a info about the computer's awakening:

Event ID 1 from the source "Power-Troubleshooter"

Does anyone know a registry value or a windows variable to check how long the computer is awake?

thx

Roman

Link to comment
Share on other sites

Romanz,

This thread may be of some use to you.

The following is an example of dumping the current 50 type 1 or 41 records from the "System" log.  This was run on a Vista OS (don't have an XP or 7 box available right now).

See the help file for more details...

#include <EventLog.au3>
#include <array.au3>

OnAutoItExitRegister('_fini')

Local $hEventLog, $aEvent, $cnt = 0

$hEventLog = _EventLog__Open("", "System")
If $hEventLog = 0 Then
    ConsoleWrite('Log failed to open' & @LF)
    Exit
EndIf

While 1

    If $cnt > 50 Then ExitLoop

    $aEvent = _EventLog__Read($hEventLog, True, False)
    If $aEvent[0] = False Then Exit
    If $aEvent[6] = 41 Or $aEvent[6] = 1 Then
        ConsoleWrite(_ArrayToString($aEvent) & @LF)
        $cnt += 1
    EndIf

WEnd

Func _fini()
    _EventLog__Close($hEventLog)
EndFunc   ;==>_fini

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi kylomas,

thanks for your help.

Meanwhile i have written my own solution:

#include <Date.au3>

Func IsAwake($MaxMin = 4)

   IsAwake = 0

   $oWMIService = ObjGet("WINMGMTS:\\.\ROOT\cimv2")

   If IsObj($oWMIService) Then

      $EventList = $oWMIService.ExecQuery("SELECT TimeGenerated FROM Win32_NTLogEvent WHERE Logfile = 'System' AND EventCode = 1 AND EventType = 3 AND SourceName = 'Microsoft-Windows-Power-Troubleshooter'")

      For $oEvent In $EventList

         ; Event Time (UTC)
         $EventDate = $oEvent.TimeGenerated
         $EventDateNew = StringLeft($EventDate,4) & "/" & StringMid($EventDate,5,2) & "/" & StringMid($EventDate,7,2)
         $EventDateNew &= " " & StringMid($EventDate,9,2) & ":" & StringMid($EventDate,11,2) & ":" & StringMid($EventDate,13,2)
         ; Current Time (UTC)
         $CurrentDate = _Date_Time_GetSystemTime()
         $CurrentDate = _Date_Time_SystemTimeToDateTimeStr($CurrentDate,1)

         if _DateDiff("n",$EventDateNew,$CurrentDate)> $MaxMin Then
            IsAwake = 0
         Else
            IsAwake = 1
         EndIf
         ExitLoop
      Next
   EndIf
EndFunc
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...