Tuesday, January 28, 2014

Stop sleeping computers from waking up at nights by themselves

It's annoying to me recently some of my sleeping computers started waking up at nights randomly. The first thing I did is to identify devices that are currently configured to wake the computer up from a sleep state in Windows by the following command line:
Powercfg -devicequery wake_armed
Below is the list of the devices returned by the command:
Standard PS/2 Keyboard
Logitech USB TrackMan Wheel
Realtek PCIe GBE Family Controller

Since I had configured the computer to allow wake-on-LAN by magic packets for a while, it is anticipated to see the device "Realtek PCIe GBE Family Controller" on the list. However, I didn't expect to see the other two devices since I didn't want any unintentional motion or events on them to wake the computer up. So what I did to disarm them from waking up the computer is:
powercfg -devicedisablewake "Logitech USB TrackMan Wheel"
powercfg -devicedisablewake "Standard PS/2 Keyboard"
The above commands runs in Windows  7 or 8 with an elevated command prompt (running the Command Prompt program with administrator privileges). Now if I query for wake_armed devices again, I only see the network adapter, which is desirable.

Another useful command for troubleshooting the unintended waking up is
powercfg -lastwake to report information about the last event that woke the computer up from sleeping. And below is what's reported from one computer:
Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Wake Timer
    Owner: [SERVICE]     \Device\HarddiskVolume2\Windows\System32\svchost.exe (SystemEventsBroker)
    Reason: Windows will execute "NT TASK\Microsoft\Windows\Media Center\mcupdate_scheduled" scheduled task that requested waking the computer.

The above tells me that the task mcupdate_scheduled is so intelligent that it woke up the computer from sleep to do its job. And it is not alone. The following command can list all such clever tasks that can wake up the computer:
schtasks /query /FO list | more

The following command can disable the task from being scheduled again:
schtasks /change /TN "\Microsoft\Windows\Media Center\mcupdate_scheduled" /disable

After disabling all these tasks, the following command can confirm that no active timers are scheduled to wake up the computer.
powercfg -waketimers

The above changes worked for me to stop sleeping Windows 7 computers from waking up at nights by themselves.