5

Example: I have a task that is scheduled for 6 am every day (only if I'm logged on). If my computer sleeps/hibernates all night until 9am, upon waking up the task will then run even though it missed its 6am schedule. I don't want that to happen as it's important that the task runs only at 6am.

I thought that unchecking the "Run task as soon as possible after a scheduled start is missed" setting would prevent this, but it doesn't. Is there another setting I should try so that the task will run only if the computer is on at the scheduled time (and will wait until the next scheduled time if it misses it)?

An example of my settings:

enter image description here

3
  • 1
    i 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
    Commented Jul 11, 2014 at 10:51
  • I'll try that out, thanks for the recommendation @konqui.
    – zants
    Commented Jul 11, 2014 at 21:36
  • 1
    Nope, 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
    Commented Jul 12, 2014 at 20:16

3 Answers 3

2

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

  1. 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,

  2. Modifying task's execution hour requires modifying the arguments to keep the task working,

  3. time /t's output depends on the regional settings.
-1

To run a scheduled task when the computer is idle, raise "Wait for Idle for:" and maybe checkmark "stop if the computer ceases to be idle".

  1. Right-click the task that you want to run when the computer is idle, and then click Properties.
  2. On the Conditions tab, under Idle Time, select the Only start the task if the computer has been idle for at least check box.
  3. Enter the length of time (in minutes) for which the computer must be idle before the task will run.

NOTE: You can also specify that any task should be stopped if the computer is in use by selecting the Stop the task if the computer ceases to be idle check box.

To understand Idle Time follow this link...

2
  • 3
    This answer appears to have nothing to do with the question!
    – kreemoweet
    Commented Jul 11, 2014 at 3:05
  • As @kreemoweet pointed out, this doesn't address my question. The task doesn't need to run when the computer is idle, I would like it to run when I'm using the computer as well.
    – zants
    Commented Jul 11, 2014 at 3:31
-1

Since you leave your computer sleeping/hibernating, then technically, you're still "logged on" (just away). So, as an alternative, you can set the task to "wake the computer to run this task" in Conditions, and it will always run at 6am. (unless you meant that you need to be at the console when the task runs)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .