Home > Software design >  Windows Task Scheduler job every two minutes
Windows Task Scheduler job every two minutes

Time:09-29

I'd like to run a Powershell script every two minutes, but either with manual start and stop OR tie it into starting and stopping when a specific application starts and stops.

I'm new to task scheduler and managed to get a task created, but could only find an "every five minutes option", and only by creating a trigger and looking at advanced options in there (and there doesn't seem to be a manual start / stop trigger).

If I then manually start the task, it runs correctly a single time, states five minutes in the future as the next run time, but doesn't actually execute at that time (status becomes "ready" after that initial manual run).

I'm certainly not opposed to considering alternatives to Windows task scheduler if there's a better option.

CodePudding user response:

  • Open "Task Scheduler"
  • On the right side click "Create Task ..." (NOT "Create Basic Task..")
  • Add a name, choose what to do in actions all according to whatever tutorial you can find. If you want more information about that, please add more information on what you're trying to achieve.
  • On Triggers, select the "One-Time"; this will be the time the schedule will start.
  • Below, tick "repeat", and where it says (by default I think) "every 5 min" edit this manually and set it to "2 minutes". Just tested it, it works.
  • Configure the "duration" as you desire, i.e. "indefinitely".
  • Create this Task by pressing the "OK" button.

Sidenote: The "Last Run Result" contains helpful debugging information. It doesn't update automatically, you have to hit the "Refresh" button on the right side for that.

From now on, you can enable/disable this task manually in the task scheduler. You could add another task that triggers when the process of your "other" application is running, which then enables/disables this task. Just meant as a hint though.

CodePudding user response:

consider something like

schtasks /create /sc minute /MO 2  /tn "Example\Test" /tr "C:\path\file.exe" /st 10:50


schtasks /delete  /tn "Example\Test"
  • Related