Windows task scheduler - Non-repeating only run during window of time

丶灬走出姿态 提交于 2021-01-24 09:41:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!