1. Home
  2. Windows Tips
  3. Run a scheduled task only once on windows 10

How to run a scheduled task only once on Windows 10

Running scheduled tasks on Windows 10 is easy given there’s a built-in task scheduler. The app allows users to run apps and scripts based on certain time based or event-based triggers. Once a task has been set up though, it will run until it is disabled. There’s no way to automatically disable a scheduled task on a given date so if you’re looking to run a scheduled task only once, you’re going to have to add an extra action to the task. The action is going to run a script that is going to disable the task. Here’s what you need to do.

Script to disable task

In order to disable a task, we’re going to use a PowerShell script. It’s easy to create but you must have already created the task that it’s going to disable because you will need its name in the script.

Open a new Notepad file and paste the following in it. Replace ‘Task name’ with the name of the task that you want to disable. Save it with the PS1 file extension.

Disable-ScheduledTask -TaskName "Task name"

Disable scheduled task

You now need to run this script so that it will disable the task in question. It is best to add this as an action to the same task that you want to disable so that you do not end up with another task running specifically for disabling the first task. That said, it is still entirely up to you and what is best for your particular use whether to run the script as an action for the same task or to create a new task that will run it.

Once you’ve created the task and added all the relevant actions to it, add one more action. Set the action to ‘Start a program’. In the Program/Script field, enter ‘Powershell.exe’. In the ‘Add arguments’ field, enter the following but replace ‘Path to PowerShell script’ with the complete path to the script that you created earlier.

Syntax

-ExecutionPolicy Bypass "Path to powershell script"

Example

-ExecutionPolicy Bypass "C:\Users\fatiw\Desktop\endTask.ps1"

Make sure that the task is set to run with admin rights. You can give it admin access from the General tab. Enable the ‘Run with highest privileges’ option. When you click OK to finalize the script, you may be prompted to enter the password for the administrator. One final thing to keep in mind is that the action that runs the script which will disable the task should be the very last one in the list of actions. You can run the scheduled task manually to see if the actions are executing in the correct order.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.