Rob van der Woude's Scripting Pages

The AT command

(NT Server and OS/2 Warp Server only)

One type of "Frequently Returning Question" in alt.msdos.batch.nt is to explain the AT syntax.
Most NT administrators know of its existence, but few know how to use it, thanks to its poor online help perhaps...

Infrequent users are advised to use WINAT from the Windows NT 4 Server Resource Kit if available.
For use in batch files, or when the Resource Kit is not available: continue reading...

 

NT syntax:

The AT command schedules commands and programs to run on a computer at a specified time and date.
The Schedule service must be running on the target computer to use the AT command.

AT [ \\computername ] time [ /INTERACTIVE ] [ /EVERY:date[,...] | /NEXT:date[,...] ] command
 
or:
 
AT [ \\computername ] [ [ id ] [ /DELETE ] | /DELETE [ /YES ] ]

 

\\computername Specifies a remote computer. Commands are scheduled on the local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled command.
/DELETE Cancels a scheduled command. If id is omitted, all the scheduled commands on the computer are canceled.
/YES Used with cancel all jobs command when no further confirmation is desired.
time Specifies the time when command is to run.
/INTERACTIVE Allows the job to interact with the desktop of the user who is logged on at the time the job runs.
/EVERY:date[,...] Runs the command on each specified day(s) of the week or month. If date is omitted, the current day of the month is assumed.
date can be specified as M, T, W, Th, F, S, Su, Monday, Tuesday, etcetera, or as 1, 2, 3, etcetera.
Note: the specified values are for English NT versions only, they are different for other language versions!
/NEXT:date[,...] Runs the specified command on the next occurrence of the day (for example, next Thursday). If date is omitted, the current day of the month is assumed.
command Is the Windows NT command, or batch program to be run, optionally followed by its parameters.
command must be an executable, so batch files should be preceded with CMD /C to be executed by AT.
Use quotes only to enclose parameters or long file names containing spaces.
command will be executed by the system with SYSTEM's access rights.

 

Debugging:

First, make sure the Scheduler service on the target computer has sufficient access rights to accomplish the scheduled task.
The default account used for the Scheduler service is SYSTEM.
So either grant the SYSTEM account sufficient access rights on the target computer or use a batch file with a user ID and password that do have sufficient access rights.

I recently found out that one of the scheduler service's great features, using any account you wish for executing the scheduled commands, seems to be missing in NT 4 workgroups. It's always the SYSTEM account there, or so it seems.

To test what goes wrong with a scheduled command, or just to see what is actually happening when it is executed, proceed as follows:

 

Examples:

Show directory listing (of \WINNT\SYSTEM32) every day at 9:39 PM:

AT \\myownserver 21:39 /INTERACTIVE /EVERY:M,T,W,Th,F,S,Su CMD /C DIR

Run a backup program (no user interaction) every Saturday at 9:00 PM:

AT \\server 21:00 /EVERY:S CMD /C "C:\Program Files\Tape\TapeBackup.cmd"

 

Alternatives:

Windows XP and later versions come with SCHTASKS, which has many more features than the AT command.

WINAT from the Windows NT 4 Server Resource Kit provides a graphical user interface for the AT command.
Recommended for occasional, interactive use, not suited for batch files.

The AT and WINAT commands are used for scheduling at absolute times.
If you need to schedule at relative times, i.e. a fixed number of seconds from now, use SOON from the NT 4 or 2000 Server Resource Kit.
Or use PMSoon.bat from my Poor Man's Admin Tools page.

As of Internet Explorer 5 and/or Windows 2000 another scheduler has been added: Task Scheduler.
The AT scheduler is still available for backward compatibility.

Task Scheduler comes with a graphical user interface.
Another, in my opinion more important, enhancement is the possibility to run each job with its own account and password. Unlike AT, which uses the SYSTEM account by default, Task Scheduler can perform jobs on other computers in the network.

The graphical user interface may be a merit to some, it is also a big disadvantage, as it prevents unattended use in batch files.
As was the case with WINAT for NT 4, the answer is provided in the Windows 2000 Resource Kit: JT.
JT allows one to enumerate, add, edit or remove scheduled jobs on local and remote computers from the command line.

JT's command line switches are far from intuitive, to say the least, so I provided a batch file to create your own JT help file in HTML format: JTHelp.bat.
Run it once, preferably in an empty directory, to create one HTML file with several associated ASCII text files.
View the sample help file created by JTHelp.bat.
Make sure JT.EXE is in the same directory or can be found in the PATH.

An example that won't make any modifications, just enumerate all scheduled tasks:

JT /SE

Or this one, which shows full details:

JT /SE P

Thanks for JSI FAQ for these examples.

More "complex" samples can be found on my JT page.

 

The following example, which does make modifications, demonstrates how to migrate Scheduled Tasks from one (Windows 2000) server to another (Windows Server 2003):

COPY \\old_w2k_server\C$\WINNT\Tasks\*.JOB \\new_w2k3_server\C$\WINDOWS\Tasks\*.*
FOR %%A IN (\\new_w2k3_server\C$\WINDOWS\Tasks\*.JOB) DO (
	JT /LJ "%%~fA" /SC domain\account password
)

This JT command assumes all tasks run with the same account. If not, you'll have to manually re-set the "Run-as" properties for each individual task.

 

Third Party Alternatives:

Have a look at VisualCron by Henrik Erlandsson.


page last modified: 2022-10-24; loaded in 0.0020 seconds