It is hard for me to boil this down, so the title is ultimately the question I suppose I need answered. Still, here is the background of my question:

I am currently trying to create a Windows task that will automatically execute a program once a month on the computers here at the office. Hours here are somewhat flexible, though, and I can't expect that people will be logged in at their computers at any particular time.

This program occasionally requires user input and creates pop-up dialogs; I do not have the option to run it in the background. It is executed via batch script, as there is file manipulation that needs to follow after the program execution. To be clear, my task's only action is to start this batch file.

I've tried the two most obvious settings:

Run task as soon as possible after a scheduled start is missed

Appears to do nothing. I wish I could find a detailed explanation of when a task is considered "missed." Apparently it does not include tasks that require the user to be logged on but whose scheduled times pass while the user is not logged on.

If the task fails, restart every...

Also appears to do nothing. I was able to make my task produce a result of (0x4) in the Task Scheduler by changing the task configuration to run when the user was not logged on. I thought it would be considered a failure, but it did not trigger any further attempts at executing the task.

I need this task to execute (1) on the first Monday of each month at 8:50 AM or (2) as soon as possible afterwards. This seems like such a simple goal and I am totally frustrated by these settings not behaving as it seems they ought to.

Will I need to learn PowerShell just to make the task run after missed starts?


You may find more information on this thread:


In my case the problem was that the user trying to run the script was not allowed to do so because of lack of permissions but the error message was completely missleading.


It's probably late for the OP, but could be useful for others.

Run task a.s.a.p. after a scheduled start is missed:

"missed" = task was not activated/launched at the trigger's time; for example, if the computer was turned off or the Task Scheduler (TS) service was busy.
Note: it will not be considered as "missed" by TS if TS didn't have to start the task accordin to your settings; for example:
-- you set to "run only when user is logged on" and computer shuts down or logged off;
-- you don't set to "wake up to run this task" and comp goes to sleep

Without that setting checked, TS doesn't reattempt the missed task instance.
With that checked, TS service will restart the task, though not immediately when TS service is again operational, but after TEN MINUTES.
BUT FOR THIS SETTING TO HAVE EFFECT: the task must, in Trigger, either have an expiry date, or set to repeat indefinitely ( probably meant the "Repeat task every x...", based on 2nd ref below)

If the task fails, restart every x units; Attempt to restart up to y times:

Here, it's only about tasks that TS managed to initiate/activate (i.e, correctly registered, and did not miss their triggers).
"Failure" is not necesarrily about the actions (part of the task, set in Action tab of Properties) executing with exit code not 0, but about TS service not managing to successfully launch each action in the task.
Once TS fails launching one of the actions, the whole task "fails" too. TS indicates "failure" of the task instance with specific event (for ex, Event 103). This failure events each can happen for many reasons - thus associated with various error codes/values, which is also the output seen in "Last result" column in the TS GUI. You would see that event either in task's history, or in Event Viewer, log of Task Scheduler (from where history of task actually takes its entries).
The run-failure event are preceded by (at least one) another failure-indicating event, closer to the origin of error. Like failure to update the task's properties correctly, or failure of TS to launch an internal module needed to run the task, or failure to launch one of the actions in the task list where the error happened (on my windows 7, event ID 203 precedes 103).... It usually has the same error code as for the ensuing task-failure event.

I could not find the list of run-failure events and their error codes for Windows 7, but, according to this link (Events and error parts redirection):
they must be very similar or same to those for server 2008 R2:
Most relevant are "Task monitoring and control" (reflecting history seen in TS GUI), with task failure event 202; and "Task Properties", with task failure events 101, 103 (which I've seen in my experience with win7). Each can be preceded by another of a variety of failure-events, that can be found within https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-r2-and-2008/dd363654(v=ws.10)

Some examples:
-- If the user interrupts the run, then it's not TS's fault, so... it's a "success" (but last result is not 0)
-- If a program is not supplied correct arguments, then it still produces an (non-zero) exit code, so TS consider it's job done => "success"
-- If you give a non-existing file as "program", then TS fails to launch it, and ... consider it "failure". Events 203 and 103 indicate it, with error codes = Last result:0x80070002; a google search gives "file not found".
And, if you select "If the task fails, restart every x units" is selected, it will attempt to restart it...

For the particular scenario of the OP:

Assuming that you can put the batch file on every target computer, in the respective user accounts, ant set a scheduled task on each of those computers:

In General tab:
set user to be the target user or group Users, and "Run only when the user is logged on" (necessary as the task requires user interraction)

In Triggers:
"Start": day 1 of the current month, 8:50AM; "On a schedule", Monthly, and select all months, and below that: "On" : First, Monday.
Then in "Advanced settings" set to "Repeat task every" (30 min or your choice), "for a duration of " (8 hours, or you know their work duration). And "Stop all tasks at end of rep. duration".

In Conditions and Settings tab: leave unchanged.

Then at the end of the batch script (before the final 'exit' if present, indicating the succesful full run of the script) need to put some code to change the properties of the scheduled task, so that it stops re-starting every x minutes for the rest of theday, as set at "Repeat task every..." above, once the script completed.
One way to do that, is to increment the task's "Start" month by one (assuming you have set day to be 1), except for month 12 - change to 1. schtasks command allows querying and changing a scheduled task.
This can be done in batch language.

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.