Writing a batch script to add a Windows startup activation task.

This post explains how to use a batch file to install a startup task with the schtasks command.

1)      Copy and paste the following text into a new batch file. This batch file can have any name and be anywhere on your computer.

schtasks /create /tn Task86 /sc ONSTART /DELAY 0000:30 /RL HIGHEST /tr C:\temp\runme.bat”

 
2)      Right click on the new batch file and select “run as administrator”.  Executing the schtasks command without administrator privileges will return “ERROR: Access is denied”.

 

3)      To verify the task was added open the windows tasks scheduler application. Programs-> Accessories -> System Tools -> Task Scheduler.

 

task scheduler screenshot

 

4)      From within task scheduler you can see the task added in step 2. The name of the task is “Task86”. This is specified by the text following the /tn parameter indicator. Every task must have a unique name. You will need to change the name parameter in the batch file to install additional tasks.

 

5)      The task wants to launch a “C:\temp\runme.bat” on startup. Create this file and copy “timeout /t 30” into it. This will open a console window for thirty seconds. Other simple test programs may execute too fast to be noticed. Alternatively you can launch a program such as   %windir%\system32\calc.exe by modifying the string after the /tr parameter indicator.

 

6)      Restart your computer. Runme.bat will execute thirty seconds after logging in and take priority over most other tasks.  The thirty second delay is caused by “/DELAY 0000:30” in the task creation command. The format is MMMM:SS. Without this delay Windows will try to launch the task before login completes which results in failure. The high priority is specified by “/RL HIGHEST” in the task creation.

 

7)      If the task did not run correctly go back to the Task Scheduler application. It will provide a task failure report.