rodent1

I need to detect wake event on windows 10

5 posts in this topic

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!

Share this post


Link to post
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

 


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Maybe this thread will help.  The code is a little old, but hopefully it helps.  

 

Adam

 

Share this post


Link to post
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

 

1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

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

  • Similar Content

    • brodillo
      By brodillo
      Hello, I've experience using automation anywhere. Now I want to learn Auto It for my automatization projects.
      I've tried to implement an example using calculator program in Windows 10.
      When I used au3Info program to identify  an escefific zone in the calc window , au3info always return the same advanced class  [CLASS:ApplicationFrameInputSinkWindow; INSTANCE:1] 
      Is there a restriction for windows 10?
      See my little script
       
      Run("Calc.exe")
      WinWaitActive("Calculadora")
      WinActive("Calculadora")
      $old="0"
      $new="1020"
      $controlNumber="[CLASS:ApplicationFrameInputSinkWindow; INSTANCE:1]"
      ControlSetText("Calculadora","",$controlNumber,$new)
      ControlSend("Calculadora","",$controlNumber,$new)
       
      I've tried using controlSetText and ControlSend.
       
      Thank you for your help
       
    • DLS
      By DLS
      I have a working script that changes the core affinity and process priority of multiples of a specific application I have running.  
      I have that part figured out.

      I would like to make a little modification to it.

      Windows10 introduced virtual desktops.  I am trying to have different core affinity and priority of processes on the visible and non-visible desktops.  
      What I need is a bool function that could be described as IsWindowOnCurrentDesktop($hWnd).  I have searched the winAPI.au3 but I do not believe anything like that exists built it.
      I have searched multiple places before asking for help. I found a Microsoft supplied example of the function I need using C#, but I am unfamiliar with C# to a degree that I cannot port the system call over.
      https://blogs.msdn.microsoft.com/winsdk/2015/09/10/virtual-desktop-switching-in-windows-10/
      Help is appreciated but not expected.  Thanks in advanced.   In the meantime I will be learning C# syntax and class structure.
    • therks
      By therks
      Does anybody know how I would go about getting the window title bar colour on Windows 10? I tried using _WinAPI_GetSysColor, and manually reading the registry (HKCU\Control Panel\Colors, ActiveTitle) but in either case I get the same (0x99B4D1, wrong) result.
      RegRead('HKCU\Control Panel\Colors', 'ActiveTitle') ; Returns 153 180 209 (aka 99B4D1) _WinAPI_GetSysColor ($COLOR_ACTIVECAPTION) ; Returns 0xD1B499 (aka 99B4D1)  
    • therks
      By therks
      As the title says, does anyone know of a way to open the Windows 10 action center using AutoIt. Maybe via rundll or some other applet?
      My intention is to just hide the normal icon, then have an AutoIt system tray icon that will open the action center on click. And I can't just send the Win+A hotkey because I have it disabled. 
      Thanks for reading.
    • TMelanson
      By TMelanson
      Hi folks,
      I'm hoping someone can help me out here.
      Background:
      I have the need to run a program with admin credentials (#RequireAdmin), and then get the SID of the locally logged in account. Not the admin account.
      If you look at the attached script, Line 16 uses the @UserName variable and returns the SID for the admin account I used to launch the app.
      I want to use line 17 which passes the result of the _GetUsername function which is a username using  ($UserName) to the WMIService.
      I'm getting " The requested action with this object has failed.:" error message.
      Any suggestions would be appreciated!
       
      test1.au3