Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Troubleshooting Windows Sleep Insomnia


:P
On this page:

This isn't anything new, but I I've struggled with Windows machines that don't stay asleep when you shut them down. It's been going on for years and across many different machines and configurations.

Right now I have 3 different Windows laptops of various makes and age, and none of them sleep properly. They pretend to sleep, but more like Sleep with one eye open: As soon as you walk away - like a petulant child - the machine wakes up and parties on its own all night long!

You know the problem, right:

  • You shut down for the night
  • The machine goes to sleep
  • You walk by the office a bit later
  • The screen is on and the machine sits at the Login screen
  • All...night...long

It doesn't stay asleep and it doesn't go to sleep again when the Windows idle timeout is reached.

Seems Windows is not sleepy...

Another favorite:

  • Close the lid or explicitly sleep the computer
  • Put it into your computer bag
  • Take the bag and computer and go about your business
  • An hour or two later take the machine out of the bag
  • It's breakfast time: You can now fry an egg on the surface of the laptop
  • The fans are ready for internal drone liftoff

Both of these happen to me all the time. New machines, old machines, machines with one set of drivers, or with others, from this manufacturer or that. It doesn't matter, Windows is an equal opportunity insomniac.

The Blame Game

Who do we blame? Windows? Hardware? Both? Yeah I blame Windows! Regardless of whether this is a hardware issue or not there should be some safeguards that prevent pointless activation.

This is a problem that simply should not happen. It's nice to be able to have some devices wake the computer, but there's a lot of things that Windows should be able to do to determine the state of the machine to figure out whether it actually should wake up. A finger print reader that activates while the lid is closed and the reader is hidden is not something that is ever useful...

Windows also could certainly provide better troubleshooting for this, given that I've heard this complaint from sooooo many people besides myself. It's low hanging usability fruit given how much of a pain this issue is, and how many people it affects. And... how often that's held up as one of the pain points Windows haters loooove to point out.

Apple certainly has that one figured out with Macs, but to be fair they control the hardware in addition to the software so they certainly have more control over what triggers system wake events. But hey even running Windows on a Mac with Parallels will cause these problems. So there's that!

Using PowerCfg

Over the weekend I ended up in a discussion of Windows problems on Twitter and I was - yup once again - complaining about the constant and very annoying sleep issues I've been experiencing.

Thanks to @philliphaydon and @hhrvoje who both pointed me at powercfg.exe which lets you check for all things that affect power operations. Using powercfg I was actually able to address the sleep insomnia.

With powercfg there are two things you can check:

  • WakeTimers
    These are operations or events (like Windows updates) that can trigger the machine to wake up.

  • Wake Armed Devices
    These are hardware devices that can trigger the machine to wake up from sleep.

Wake Timers

In my case I don't have any Wake Timers on my machine, so there's no hardware or software drivers that trigger waking up the computer.

To check of you have any Wake Timers:

# list wake timers
powercfg /waketimers

# show last item that woke Windows
powercfg /lastwake

Since I don't have any devices that are using wake timers I couldn't play around with this much, but if you have one that wakes up you can use the Device Manager settings to disable the wake up features for the device(s) listed or temporarily disable the device(s) to see if that helps.

Wake Armed Devices

The second and probably more important option lets you worked with armed devices which are devices that have sleep waking enabled.

There are three commands in powercfg:

  • powercfg /devicequery wake_armed
  • powercfg /devicedisablewake
  • powercfg /deviceenablewake

In my case putting it all together looked like this:

# list devices
powercfg /devicequery wake_armed
"Goodix fingerprint"

# disable wake for specific device
powercfg /devicedisablewake "Goodix fingerprint"
  
# reenable  wake for specific device
powercfg /deviceenablewake "Goodix fingerprint"

The /devicequery command has a number of options you can work with powercfg /devicequery /? but for this discussion the wake_armed parameter is probably the only one that is significant.

As you can see above, the only device that is armed (according to the command anyway) is my Fingerprint Reader on this Dell XPS 15. Once I disabled the device wake option, my machine now gets a good night's rest both when I put it to sleep explicitly at night and when I close the lid and stick it in a bag to carry around.

For the last 3 days - no problems with random wake ups and no fried eggs after bagging it either. Yay!

Oddly though, I know that there are other devices that will wake the computer. The mouse and keyboard certainly will bring the laptop back from the dead, as will the lid and powerbutton obviously. None of these devices show in the /devicequery, but perhaps these are the base, essential devices that are not even considered in the list of uh... potential wake event abusers.

Using Device Manager

Besides powercfg you can also use Device Manager to enable and disable device wake settings. If you want to go that route you can find the device in Device Manager and use the Power Management Settings to toggle the Allow this device to wake the computer setting:

This is the same setting that powercfg /devicedisablewake actually affects when enabling/disabling with the command line tool.

Although you can use Device Manager for enabling disabling there are no UI tools that let you find or suggest devices that affect the wake state, so most likely you'd be using the powercfg command line tool anyway, at which point you might as well enable and disable using powercfg. 🤷

Summary

Sleep insomnia of Windows machines is a big Windows pain point. I know just about every machine I use has this problem and I'll be looking at all the others to see if there are devices that are triggering the machines to wake up on those too.

It sure would be nice if there was a more obvious way to find this functionality rather than some obscure command line tool. Like a nice link to a tool in the Power Options Control Panel applet or heck even an info bubble help item pointing to more info on powercfg would do the trick. Or better: Show a list of devices that can cause the computer to wake up would be nice somewhere in the UI where you can find. Even linking to documentation from there would help.

But alas once you know about powercfg it's an easy way to find devices and if necessary turn them off.

This is not new, nor unknown if you search around. I think I looked at this in the past for another machine but in the years that have passed since I've forgotten how to do this. So once again I'm writing a blog post to jog my memory. Hopefully it's useful for a few of you too as it was for me (repeated or not 😄)...

this post created and published with the Markdown Monster Editor
Posted in Windows  

The Voices of Reason


 

Alex Sarafian
March 04, 2020

# re: Troubleshooting Windows Sleep Insomnia

I had a similar issue in the past when Microsoft was much more aggressive on their Windows updates policies.

It turns out that a job is created to restart the computer to make sure that it can apply the updates. Even when disabling, the system will at some point create it again. So I had to create a schedule job to disable the job that shows up now and then. I think now Microsoft is less aggressive with the job re-creation but it still happens. My setup is a desktop machine and if something like this happened on my laptops I would be annoyed. But the professional laptops I worked with I never had such issues. Maybe the policy differs between desktop and laptops although the lines are becoming grey.

More on this if you are interested here. I hope this also helps others.


Alexandre Jobin
March 04, 2020

# re: Troubleshooting Windows Sleep Insomnia

Thank you for your article. I do have this problem on all my laptops and I burned the screen of my last one because it stayed on the login screen all the week-end.

I will try the commands that you have suggested for sure.


Jesse Slicer
March 04, 2020

# re: Troubleshooting Windows Sleep Insomnia

My only one left is TASKS\Microsoft\Windows\UpdateOrchestrator\Backup Scan and nothing I seem to do can touch that task. I hope the other ones I was able to shut off solve the problem. Thanks for all the great info!


André Cardoso
March 05, 2020

# re: Troubleshooting Windows Sleep Insomnia

I got into the habit of hibernating the laptop for the night/weekend (and having it eat disk for hibernating)… But since a few months whenever I hibernate it, the next morning I lose my 3 monitors configuration (it's all Dell) and have to resort to disabling and enabling the Graphics card: Get-PnpDevice| where {$_.friendlyname -like "IntelHD Graphics"} | Disable-PnpDevice -Confirm:$false


Frank
March 06, 2020

# re: Troubleshooting Windows Sleep Insomnia

Thanks for a great article, I also struggled with insomnia issues on my Windows 10 when attempting to sleep. On my system, there was also a couple of wake timers active.

To turn them off completely, you can

  1. Open the Control Panel.
  2. Click on "Power Options" and select "Change Plan Settings" for the power plan that is in use.
  3. Click on "Change Advanced Power Settings" and expand "Sleep".
  4. Expand "Allow Wake Timers" and disable it.

Rick Strahl
March 08, 2020

# re: Troubleshooting Windows Sleep Insomnia

@Frank - that sounds nice but I don't have those sleep settings unfortunately. I merely see Sleep After and Hibernate After with times. No options for wake anything unfortunately.

Those used to be there, but apparently Microsoft has buried those even further away.


David Elyk
March 25, 2020

# re: Troubleshooting Windows Sleep Insomnia

Replying to @Jesse

I just ran across the same issue and finally tracked it down.

That Backup Scan is being run by windows task scheduler and if you try to make changes you will get a permission error even if you are running as Administrator.

Task Scheduler is set to run as SYSTEM, so you either have to grab ownership, make your changes, then set it back (I guess?) to SYSTEM.

-Or-

I installed Psexec.exe from Sysinternals and invoked Task Scheduler with it:

psexec -sid %windir%\system32\mmc.exe /s taskschd.msc

Then you can make changes and actually save them.

Task Scheduler Library > Microsoft > Windows > UpdateOrchestrator Click Properties > Click Conditions Tab

Now you can clear the Wake the Computer to run this task checkbox


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024