≡ Menu

Schedule tasks from command line

Schedule tasks‘ is a GUI application using which we can schedule tasks, There is an equivalent utility which provides the same functionality but with the advantage that it can be used from windows command line. This command is Schtasks. This is an in-built windows command supported by XP, Vista and Windows 7. Let’s see the syntax of this command with the help of few examples.

How to schedule a task ?

If you are logged into the same computer where you want to run the scheduled task, then you can use the below command to create the task.

Schtasks create /RU username /RP password /SC schedule_frequency /MO Schedule_modifier /D days /M months /TN taskname /TR Task_command /ST start_time /SD start_day /ED end_date

Now let’s see few examples.

Example 1: Schedule disk defragmentation on every Saturday at 10AM. User credentials are administrator/password.

Schtasks /create /RU administrator /RP adminpassword /SC weekly /D SAT /TN defrag /TR c:\windows\system32\defrag.exe /ST 10:00:00

If the specified username and password are correct, then you would get the below message when you run the above command.

SUCCESS: The scheduled task "defrag" has successfully been created.

If the credentials are not correct, you may get a warning like below.

WARNING: The Scheduled task "defrag5" has been created, but may not run because the account information could not be set.

If there exists a scheduled task with the same name then the error would be:

specified task name already exists in the system.

If you need to use a domain user account to run the task you can specify domainname\username with /RU option.

How to get the list of scheduled tasks?

Just run Schtasks command and you can see the list of scheduled commands.

C:\>schtasks

TaskName                             Next Run Time            Status
==================================== ======================== ===============
defrag                               10:00:00, 3/12/2011
GoogleUpdateTaskUserS-1-5-21-3567637 11:14:00, 3/6/2011
GoogleUpdateTaskUserS-1-5-21-3567637 13:14:00, 3/5/2011

If you want complete details about each of the tasks you can run the command ‘Schtasks /query /v

Delete  a scheduled task

We can delete a schedule task using ‘schtasks /delete /TN task_name‘ command.  For example, to delete the task we created in the example 1 we can run the below command.

Schtasks /delete /TN defrag

Delete all the scheduled tasks

You can run the below command to delete all the scheduled tasks.

schtasks /delete /TN *

Disable a scheduled task

There does not seem to be a way to disable a scheduled task from command line. We can delete the tasks as mentioned above.

Modify  a scheduled task:

We can change a scheduled task using ‘schtasks /change’ command. Run ‘schtasks /change /?’ for the syntax.

 

14 comments… add one
  • Alex

    how to delete from the folder?

  • vlci

    schtasks /delete /TN “Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser” /F

  • Yavor

    It is possibile to disable sheduled task. Here is an example:
    schtasks /Change /TN “Microsoft\Windows\MUI\LPRemove” /Disable

  • chanchinliana

    Thank you all.

  • Neo

    How do you do it if the task is meant to be run on a DIFFERENT computer (like with the “connect to another computer”)? Thank you! On cmd please.

    • B

      Use:
      schtasks /s

  • Nikolaus MEURY

    Hello,

    I’m regarding to run a batch file by a schedule task.

    This script is running chrome with a specific url.

    The problem is that I must choose some credential in my command line like this :
    schtasks /create /sc once /tn Video_XP /tr “\\myserver\myscript.bat” /u contoso\admin /p mypassword /st 12:25:00

    The problem is that the task is running with an other account than the login one.

    If I replace /u by %username% i’m not able to specify the passord and the task will stuck in background requesting password.

    Any ideas ?

  • Rohan

    Please tell how can I know whether a task is Enabled/Disabled using CMD queries
    Please provide a Example supporting your answer.

  • yasir

    what to add in cmd for sidebar execute properties, setting,
    for this two things:
    if the task fails, restart every: 30 minutes
    also deselect stop the last if it runs longer den

  • Aravind

    Can I get the command to enable “Run whether user is logged in or not” option while scheduling task from command line.

    Thanks in advance

  • Indigo Taylor

    Hello everybody!
    I was forced to use win10 –
    lot’s of automatic pop ups, reminders and other annoying stuff
    called “features”. However:
    My company is constructing high-level measurement devices.
    (i’m doing electronics)
    our win-develloper just committed suicide and i’m left with the crap…
    (just kidding)
    Please help me!
    A pop up that wanted to update or install language-support popped up
    and tried to connect to www to do some updates – Why?! The sys was running fine!
    Since our devices are ment to work headless but only with a remote-access,
    there will be no connection to www ever… So:
    Q1) how to get win10 a bit more www-independent?

    Back to the pop-ups: As a source of evel, i identified schtasks…
    I don’t consider it smart, to have a let’s tidy-up-the harddrive-task starting in the bg,
    or debugging when our customer just wants to shut down the system and is forced to wait.

    So, what will be damaged (especially concerning wifi) when i just do
    schtask /TN * /delete?

    Thanks a lot for your answers!
    (Sorry for my upset state…)
    indigo

  • viki

    schtasks /Create /tn “mytask” /sc MINUTE /mo 1 /ru “myuser” /rp “mypassword” /tr “C:\Windows\System32\calc.exe”
    this command does not run calculater.
    Any help in this?

    • James Haynes

      schtasks /Create /tn “mytask” /sc MINUTE /mo 1 /tr “C:\Windows\System32\calc.exe”

      i guess you can run calc as a dif user, but no need to if youre just trying to add something. otherwise your syntax was incorrect and idk what your username and password were.
      and you will want to run this after you get the above correct unless you want to see the calc open up every minute… ;)

      schtasks /delete /TN mytask

  • Frodo

    Hi nice tutorial and blog

    How to setup a task to run a c:\myfile.bat once a week on login from command line?

Cancel reply

Leave a Comment