问题
I've set up a non-repeating task which is triggered by workstation unlock. How can I condition it so that only runs within a specific period of time during the day? For example just between 8-10 A.M?
There's a similar question answered before but that solution can only be used for a repeating task.
回答1:
I was hoping for an answer, came back and there was nothing but since I needed one badly enough I found it myself. This process always amazes me.
You need to do your task via a batch file using IF
command. Here's the code:
@ECHO OFF
:: For using just the hour digit of 'time' variable
SET hour=%time:~0,2%
:: Let's say I want whatever it is to run only when I'm unlocking the station between 8-10 A.M.
IF %hour% GEQ 8 IF %hour% LEQ 10 (GOTO RUNIT)
GOTO END
:RUNIT
:: Put your commands here, I want to open a bunch of text files I'm working on.
start notepad "D:\file1.txt"
start notepad "D:\file2.txt"
:END
Works like charm. Now those file won't open every time I'm back to my laptop and log in.
来源:https://stackoverflow.com/questions/61402422/windows-task-scheduler-non-repeating-only-run-during-window-of-time