3

https://c1.staticflickr.com/1/623/22056481124_6cb41164ee_b.jpg
Wake History Count - 1
Wake History [0]
Wake Source Count - 1
Wake Source [0]

https://c1.staticflickr.com/1/763/21680581753_ce45aa17a1_b.jpg
Wake History Count - 1
Wake History [0]
Wake Source Count - 0
(No Wake Source is shown)

If I press a key to wake my computer from the sleep mode, the result will be the one shown in screenshot 1.
If the computer wakes up unexpectedly, the result will be the one shown in screenshot 2.
I have tried various methods, but there is actually no way to prevent the computer from waking up unexpectedly.
The problem did not arise until I upgraded my Windows 7 to Windows 10 last month, so I think the problem lies in Windows 10 instead of my computer, to which no hardware changes have been made.
In Event Viewer, the events that happen when it wakes up unexpectedly are exactly the same as those that happen when it wakes up normally (i.e. I wake it manually)
In Power settings, under Conditions, waking the computer to run the task has been disabled.
By means of Task Scheduler, a .bat file can be run automatically whenever the computer wakes up, whether unexpectedly or normally.
What commands can be used in the file so that the computer will automatically go to sleep again whenever it wakes up unexpectedly?

1

Try this:

powercfg -lastwake | findstr /I /C:"Type:"
if %errorlevel% == 0 (
    echo woken up by something
) else (
    echo woken up unexpectedly
)

In short, it just looks for Type: in the output of powercfg -lastwake and if it doesn't exist then assumes that the machine woke up unexpectedly.

If you want to actually make the machine go back to sleep then replace the second echo with the following:

powercfg -h off
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
powercfg -h on

Bear in mind that your computer could get into a loop where it wakes, runs this script, goes back to sleep, wakes, runs this script, goes back to sleep and so on and so on.

  • On my computer, if %errorlevel% == 0 does not work, but if errorlevel 0 does. – Matthew Wai Nov 2 '15 at 15:06
  • I have just tried it. When it wakes normally, the Type: will be 0 and 1. When it wakes unexpectedly, the Type: will also be 0 and 1. There are no differences. What can I do? – Matthew Wai Nov 4 '15 at 9:11
  • Why are you disabling and enabling hibernate? That seems totally unneeded? – Tonny Nov 4 '15 at 11:18
  • No, I have deleted powercfg -h off and powercfg -h on and just use rundll32.exe powrprof.dll,SetSuspendState 0,1,0. The problem is that the errorlevel of normal waking is the same as that of unexpected waking. I have tried if errorlevel 2, but that is not the result of both normal and unexpected waking. – Matthew Wai Nov 4 '15 at 11:58
  • @Tonny I found that if you don't disable hibernate first then rundll32.exe powrprof.dll,SetSuspendState 0,1,0 will hibernate the computer rather than put it to sleep. If there is a better way to do this then I'm all ears! – Richard Nov 4 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.