I found a workaround: make your task launching your .bat
script, which will launch the command if it discovers computer wasn't asleep. Script I use is:
@echo off
for /f "delims=" %%t in ('time /t') do if "%%t"=="%1" %~2
This script takes two parameters: first is time when the command is intended to be called, and the second is command itself, in quotes, like script.bat 21:40 "echo x"
.
Explanation
Unlike in Bash, in Batch it's impossible to directly store command output in variable, but one can iterate over it's output line after line. That's what my second line does. Because time /t
's output
is single line, there is only one iteration, in which the script launches the command (passed as second parameter) if script was called when you wanted it to be called; this condition will not be meet when this is delayed execution of the script.
I use %~2
instead of %2
, because %~2
discards quotes around command,
so that passing "echo x"
will execute echo
with argument x
, printing x
,
instead of invoking program echo x
with no arguments.
Drawbacks
Launching task on demand will do nothing, you'd better uncheck field Allow task to be run on demand in the Settings tab, not to be confused by that,
Modifying task's execution hour requires modifying the arguments to keep the task working,
time /t
's output depends on the regional settings.
1i see that you have enabled that the task should be run every 5min if it fails. As far as i know a task which time has passed and it hadn't been run is treated like a failed task. So it may be due to that Checkmark. – konqui – 2014-07-11T10:51:21.677
I'll try that out, thanks for the recommendation @konqui. – zants – 2014-07-11T21:36:44.353
1Nope, that didn't do it either :( There's the normal wait as the computer comes out of sleep, and then a few seconds later all of my tasks fire off at once. – zants – 2014-07-12T20:16:20.950