Jump to content

I need to detect wake event on windows 10


Recommended Posts

Hi,

I have an Asus transformer tablet with Windows 10 32 bit. When I close it, it goes to sleep. When asleep, wifi is turned off. There is a WM_POWERBROADCAST message that is supposed notify applications that a power-management event has occurred, such as waking up. When the tablet wakes, it does not turn wifi back on. So I wrote a script to check the message, and sure enough, it does not fire. I was going to use that to force start wifi on wake up. I'm looking for an idea to get around that. But so far, I don't have anything. Besides complaining online about Microsoft or Asus bugs, does anyone have ideas?

Thanks!

Link to comment
Share on other sites

$gobjWMI_CIMV2 = ObjGet("winmgmts:\\.\root\cimv2")
$gobjWMI_PowerEVT_Sink = ObjCreate("WbemScripting.SWbemSink")
ObjEvent($gobjWMI_PowerEVT_Sink, "__PowerEVT_SINK_")
$gobjWMI_CIMV2.ExecNotificationQueryAsync($gobjWMI_PowerEVT_Sink, "Select EventType from Win32_PowerManagementEvent")

While Sleep(100)
WEnd

Func __PowerEVT_SINK_OnObjectReady($wmiObject, $wmiAsyncContext)
    Switch $wmiObject.EventType
        Case 7
            MsgBox(64+262144, Default, "OS reports resume from suspend is complete", 0)
            ShellExecute(@ScriptDir & "\force_start_wifi.exe")
    EndSwitch
EndFunc   ;==>__PowerEVT_SINK_OnObjectReady

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Hi Exit,

Thanks for your post. It looks like it should work. But it went through several sleep and wake cycles, and it did not work.

The __PowerEVT_SINK_OnObjectReady function never fired. To check that, I added a logging function at the top of the function, and got no log.

I also tried it as administrator, just in case an app needs special rights to receive those messages, which in this case would be odd, That did not help anyway.

Here is the code:

$gobjWMI_CIMV2 = ObjGet("winmgmts:\\.\root\cimv2")
$gobjWMI_PowerEVT_Sink = ObjCreate("WbemScripting.SWbemSink")
ObjEvent($gobjWMI_PowerEVT_Sink, "__PowerEVT_SINK_")
$gobjWMI_CIMV2.ExecNotificationQueryAsync($gobjWMI_PowerEVT_Sink, "Select EventType from Win32_PowerManagementEvent")

While Sleep(100)
WEnd

Func __PowerEVT_SINK_OnObjectReady($wmiObject, $wmiAsyncContext)
    AddToLog($wmiObject.EventType, @ScriptDir & "\" & "EventList.log")
    Switch $wmiObject.EventType
        Case 7
            MsgBox(64+262144, Default, "OS reports resume from suspend is complete", 0)
            ShellExecute(@ScriptDir & "\force_start_wifi.exe")
    EndSwitch
EndFunc

Func AddToLog ( $What, $LogFileName)
dim $File
    $File = FileOpen ( $LogFileName, 1 )
    If $File = -1 Then Return
    FileWriteLine ( $File, @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @TAB & $What & @CRLF )
    FileClose ( $File )
EndFunc

In case that's relevant, the tablet runs Windows 10 home 32 bits with a quad core cpu, Z3775.

Thanks!

Link to comment
Share on other sites

I changed the Case statement
from :           Case 7
to:                 Case 6,7,8

$gobjWMI_CIMV2 = ObjGet("winmgmts:\\.\root\cimv2")
$gobjWMI_PowerEVT_Sink = ObjCreate("WbemScripting.SWbemSink")
ObjEvent($gobjWMI_PowerEVT_Sink, "__PowerEVT_SINK_")
$gobjWMI_CIMV2.ExecNotificationQueryAsync($gobjWMI_PowerEVT_Sink, "Select EventType from Win32_PowerManagementEvent")

While Sleep(100)
WEnd

Func __PowerEVT_SINK_OnObjectReady($wmiObject, $wmiAsyncContext)
    Switch $wmiObject.EventType
        Case 6,7,8  ; RESUME CRITICAL/SUSPEND/STANDBY = 6/7/8
            MsgBox(64+262144, Default, "OS reports resume from suspend is complete", 0)
            ShellExecute(@ScriptDir & "\force_start_wifi.exe")
    EndSwitch
EndFunc   ;==>__PowerEVT_SINK_OnObjectReady

 

App: Au3toCmd              UDF: _SingleScript()                             

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...