问题
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