[Windows] I want to register a task that "executes at logon and then repeats infinitely every 〇 hours" in the task scheduler with a command!


hello!This time, I would like to introduce a command to register a schedule that executes a task at logon and then keeps executing it again periodically.

It is easy to schedule a task that you want to execute in a single shot or a process at logon, but surprisingly, you cannot register a task schedule that you want to execute in combination with a straightforward method.

In order to achieve this, there is no way to create a script that is executed regularly, but I could register it only with the task scheduler with a little ingenuity, so I would like to post the method.

Thing you want to do

"When logging on to any user - After being triggered, repeat indefinitely every 〇 hours.I want to create a task with a command.

State of the actually registered task scheduler

Normally, the logon task of any user is "schtasks / create". / sc onlogon You can create it with "~~".

Similarly, the task that repeats every 〇 hours is "schtasks / create". / ri 〇 You can create it with "~~".

But "schtasks / create" / sc onlogon / ri 〇 ~~ "Error when using options togetherWill occur. (As shown in the image below)

Here's how to avoid this.

Script example

schtasks /create /tn "TESTTASK" /tr "C:\TEST.exe" /sc onlogon
schtasks /change /tn "TESTTASK" /ri 60


schtasksThe command isCommands for operating the task scheduler.

I think that there are many people who register the daily movement of files on a personal computer as a batch file.

Option to execute at "at logon of any user"

Usually, "/ sc onlogonWith the "" option, "When logging on to any userYou can create a task to be executed.

schtasks / create / sc onlogon / tn "TESTTASK" / tr "c: \ test.exe"

"Repeat every XNUMX minutes after execution" option

In addition, as follows/ ri 〇With the "" option, "After execution, repeat every 〇 minutesYou can create a task.

schtasks / create / ri 5 / tn "TESTTASK" / tr "c: \ test.exe" /sc monthly

Error when used together

However, when used together, "/ sc onlogon"When"/ ri 〇"Cannot be used together" will result in an error.

To avoid errors

To avoid this error, the command is divided into two lines as follows.

(XNUMX) Create a task at "when any user logs on"

(XNUMX) Add (change) the "Repeat every XNUMX minutes after execution" setting in the "/ change" option.

schtasks / create / tn "TESTTASK" / tr "C: \ TEST.exe" / sc onlogon
schtasks / change / tn "TESTTASK" / ri 60

Divide into two linesso,"Executed when any user logs on, and then executed at regular intervals (repeat)"It realizes the creation of tasks to be performed.


This time, I introduced how to create a task that "executes when any user logs on and then repeats at regular intervals" with a command.

Intuitively, it feels like you should use the "When any user logs on" and "Run at regular intervals" options together at once.

In reality, these options cannot be used together.However, I was able to add and change it so that it will be executed regularly after it is created.

When creating a task that "executes when any user logs on and then repeats at regular intervals", try using the command introduced above.

I hope it helps you.


Translate »
I copied the title and URL