question

BenjaminJ-0475 avatar image
0 Votes"
BenjaminJ-0475 asked BenjaminJ-0475 commented

Task scheduler - Condition on time of day

I want to set a task to run on log on, but only if the time lies in a predefined range, e.g. between 08:00 and 20:00.

Is there a way to do this with task scheduler?

If not, what would be the recommended alternative? Interpose a powershell script and check the time in that?

Background:
I want to set the sound output device (using NirCmd) depending on the time.
The task is triggered at 08:00 and that works, but if I log on at e.g. 09:00, I want it to trigger also then.

windows-10-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Reza-Ameri avatar image
1 Vote"
Reza-Ameri answered BenjaminJ-0475 commented

If you right click on the task and click on Properties then in this menu go to Settings and check the box Run task as soon as possible after a scheduled start is missed and it will perform the task as soon as you start your system and the time have been missed.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Reza-Ameri, that might work.

I'll have to see however how it behaves if Logon should happen after 20:00.
At that time I have set up another task that switches output to headphones.
It should also run later if scheduled start is missed.
Since their actions are competing it might result in a race condition.

Basically my goal is that sound output is automatically set to speakers during the day (8:00 to 20:00) and to headphones during the evening/night.
I think I have to go with an interposed script to avoid race conditions.

Your option might prove useful for other tasks however

0 Votes 0 ·
CarlFan-MSFT avatar image
1 Vote"
CarlFan-MSFT answered BenjaminJ-0475 commented

Hi,
Open Task Scheduler.
Create task
Triggers tab
New ...
Use the following settings
You don't need to stick with the pre-defined times - you can type into these fields any value you wish.
93932-capture2.png


In "for a duration of" you could enter the amount of minutes you want it to run for.
Also you could select the options under Settings below:
93952-capture3.png


Hope this helps and please help to accept as Answer if the response is useful.
Best Regards,
Carl



capture3.png (17.1 KiB)
capture2.png (19.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your efforts but I don't think that works for my scenario (see my other comment for details on that)

Repeating the task every hour isn't necessary.
It has to run only once, but under the right conditions that task scheduler sadly seems unable to support.

At least I don't see a way to limit the option "Run task as soon as possible after a scheduled start is missed" to a time frame (if log on happens after 20:00 it should not run)

0 Votes 0 ·