Put computer in standby after running a scheduled task but only if it had to wake up to run it

泪湿孤枕 提交于 2019-12-12 05:14:33

问题


I have a scheduled task which I want to run every few hours. If the computer is currently in standby, I want it to wake up, run the task, then go back to sleep. If the computer is currently on, I want it to run the task but not go back to sleep, because that would be annoying.

Is there any way of knowing whether a scheduled task had to wake the computer to run?


回答1:


I've just realised one way of doing it which is to run powercfg -lastwake

This is the output when waking to run a task:

C:\Users\will>powercfg -lastwake
Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Wake Timer
    Owner: [SERVICE] \Device\HarddiskVolume5\Windows\System32\svchost.exe (Schedule)
    Owner Supplied Reason: Task Scheduler will execute '\test' task.

This is the output normally:

C:\Users\will>powercfg -lastwake
Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Fixed Feature
    Power Button


来源:https://stackoverflow.com/questions/27765784/put-computer-in-standby-after-running-a-scheduled-task-but-only-if-it-had-to-wak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!