samedi 11 avril 2015

Where is GetThreadExecutionState in the Windows API?

I have noticed that there are situations where Windows machines refuse to go to sleep when I expect them to. I know that certain applications like Windows Media Player, or a web browser when it's on Youtube, are able to prevent the system from going to sleep. But sometimes it is a mystery exactly which application is preventing the system from going to sleep. Furthermore, the command powercfg.exe /REQUESTS often does not return any results... and yet... the system will not go to sleep.


I know that one could use the SetThreadExecutionState Windows API function to tell the system not to go to sleep... but what if I wanted to query a thread's execution state in order to see whether the thread has an execution state that would prevent the system from going to sleep?


1 commentaire:

  1. I was looking for the answer to the same question and I found out that, if the function SetThreadExecutionState succeeds, it returns the previous execution state.

    As next step I tried to pass the value 0 as parameter and, by doing so, it seams the function does not change the current state, but still returns it.

    I think this could be a working solution.

    RépondreSupprimer