How to Schedule a Task to Run at a Specific Time (Legacy AT Command)
Before the modern and powerful schtasks.exe utility became the standard, the original command-line tool for scheduling tasks in Windows was the AT command. While AT has been officially deprecated and is much less flexible than schtasks, it still exists on all modern versions of Windows for backward compatibility. It provides a very simple, direct way to schedule a command to run once at a specific time in the near future.
This guide will explain how to use the AT command to schedule a simple one-time task. We will cover its simple syntax, its critical prerequisites, and highlight its many limitations, explaining why schtasks is the recommended tool for all modern scripting.
CRITICAL: AT vs. schtasks (Why AT is Legacy)
It is essential to understand that the AT command is a legacy tool. It has been superseded by schtasks.exe.
| Feature | AT Command (Legacy) | schtasks Command (Modern) |
|---|---|---|
| Complexity | Very Simple. Easy syntax for one-time tasks. | Powerful and Complex. Can create highly detailed recurring schedules. |
| Recurrence | No. Can only schedule a task to run once. | Yes. Can run daily, weekly, monthly, on logon, etc. |
| User Context | Runs as the SYSTEM account. | Can specify any user account (/RU). |
| Interactivity | /interactive switch allows it to interact with the desktop. | Cannot directly run interactive tasks. |
| Status | Deprecated. Microsoft can remove it in future Windows versions. | Current and Recommended. The standard for all task automation. |
Rule of Thumb: Use schtasks for any serious, persistent, or recurring task. Use AT only for very simple, "fire and forget" tasks that need to run once, soon.
The Core Command: AT
The AT command adds a job to the Task Scheduler's queue.
Syntax: AT [\\computername] time [/interactive] "command"
[\\computername]: An optional remote computer to schedule the task on.time: The time to run the command, inHH:MM(24-hour) format./interactive: Allows the task to interact with the desktop of the user who is logged on at the time the task runs."command": The command, script, or program to be executed.
This command must be run with administrator privileges.
Prerequisite: The Task Scheduler Service Must Be Running
The AT command is a front-end for the Task Scheduler service (Schedule). If this service is stopped or disabled, AT will fail.
Exmaple of error message:
The service has not been started.
Solution: Ensure the "Task Scheduler" service is running. A robust script would check this first with SC QUERY.
Basic Example: A Simple One-Time Task
This script schedules a DIR command to run in 2 minutes from the current time and save its output to a file.
@ECHO OFF
REM This script MUST be run as an Administrator.
ECHO --- Scheduling a one-time task with AT ---
ECHO.
ECHO This will run a DIR command in 2 minutes.
REM Note: You would need to manually calculate the future time.
REM Let's say the current time is 14:30.
AT 14:32 "cmd /c DIR C:\Users > C:\Logs\dir_log.txt"
IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] The task was scheduled successfully.
) ELSE (
ECHO [FAILURE] The command failed.
)
How to View and Delete AT Jobs
- To View: Running
ATwith no arguments will list all the jobs that have been scheduled with theATcommand. Each job is assigned a unique ID. - To Delete: Use the
/DELETEswitch with the job ID.
C:\> AT
Status ID Day Time Command Line
-------------------------------------------------------------------------------
1 Today 2:32 PM cmd /c DIR C:\Users > ...
C:\> AT 1 /DELETE
Common Pitfalls and How to Solve Them
Problem: "Access is denied." (Administrator Privileges)
This is the most common failure. Scheduling tasks is a privileged operation.
Solution: The script must be run from an elevated command prompt. Right-click your .bat file or cmd.exe and select "Run as administrator."
Problem: The Command is Deprecated
When you successfully schedule a job, you will see a warning message.
Exmaple of warning message:
Warning: The AT command has been deprecated. Please use schtasks.exe instead.
"AT" will be removed in a future release.
Added a new job with job ID = 1
Solution: Heed the warning. For any new script, you should learn and use schtasks. The AT command should only be used if you are maintaining a very old script or have a specific need for its simplicity.
Practical Example: A "Delayed Shutdown" Script
This is a task for which AT is still reasonably well-suited. The script schedules a system shutdown to occur at a specific time later that day.
@ECHO OFF
SETLOCAL
REM This script MUST be run as an Administrator.
TITLE Delayed Shutdown Utility
ECHO --- Delayed System Shutdown ---
ECHO.
SET /P "ShutdownTime=Enter the time for shutdown (24-hour HH:MM format): "
IF "%ShutdownTime%"=="" (ECHO Invalid time. Aborting. & GOTO :End)
ECHO.
ECHO WARNING: This will schedule the computer to shut down at %ShutdownTime%.
PAUSE
AT %ShutdownTime% "shutdown /s /f /c \"Scheduled shutdown initiated by script.\""
IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] The shutdown has been scheduled.
ECHO To cancel, open a command prompt and type 'AT', find the job ID,
ECHO and then type 'AT <ID> /DELETE'.
) ELSE (
ECHO [FAILURE] Could not schedule the shutdown.
)
:End
ECHO.
PAUSE
ENDLOCAL
Conclusion
The AT command is a simple, legacy tool for scheduling one-time tasks. While it has been replaced by the far more capable schtasks, it remains a quick and easy option for simple "run this command later" scenarios.
Key takeaways:
ATis deprecated and should be avoided in favor ofschtasksfor modern scripts.- You must run the script as an Administrator.
- The command only schedules tasks to run once. It does not support recurring schedules.
- The Task Scheduler service must be running for
ATto work.