I know there is the at and schtasks. But I couldn't figure out how to use them to execute a task soon and once. I have read about a soon command, but there isn't such command in my Windows version.

I plan to include this command in a batch file and, because of that, I can't hardcode the start time.


The schtasks command can run a defined task immediately.

From How to use Schtasks.exe to Schedule Tasks in Windows Server 2003

Schtasks /Run

Starts a scheduled task immediately. The run operation ignores the schedule, but uses the program file location, user account, and password that are saved in the task to run the task immediately.


schtasks /run /tn TaskName [/s computer [/u [domain\]user /p password]] /?

So just define the task, then run it immediately at any time you need to.

  • I just need to know now how to create a scheduled task without a schedule, to use your solution. Otherwise I could risk running it twice. – Jader Dias Feb 13 '11 at 16:14
  • You could define a schedule that can never be executed. You might also try /Run of a disabled job - it might work (the documentation doesn't say no). – harrymc Feb 13 '11 at 16:30

Working on top of Keith's answer to suit your needs:

timeout /t X ; psexec -i -s Y


  1. timeout replaces sleep in Windows 7.
  2. X is the seconds to wait defined by /t, add /nobreak if you want to disallow the user to continue.
  3. psexec from Microsoft SysInternals allows you to run interactive (-i) as the local system (-s), please note that you have to start psexec once to accept the first time EULA, or add -accepteula.
  4. Y is your command.

runas doesn't allow you to start as local system, that's why to use PsTools for process-related tasks.
Starting a Scheduled Task or Service seems like too much of a workaround for me...

For example, Patrick's answer can simply be rewritten as:

timeout /t 120 ; psexec -i -s calc.exe
  • +1 for timeout's simplicity. at complained on me in Windows 7. And although schtasks allows you to simply enter the target time (and possibly date) - whereas with timeout you have to calculate the number of seconds until that time yourself - when you want to run something at a certain time, you have to first schtasks /create it, and later schtasks /delete it, otherwise it will linger around. Why would you want to store global (and permanent) state for a one-off task anyway? This also forces you to choose a unique name so as not to overwrite some existing task? – Evgeniy Berezovsky Jun 5 '14 at 23:44

This starts calc.exe in 2 minutes. Change the

set /A START_MIN=%%j + 2

line to change the time interval.

for /f "delims=:. tokens=1,2" %%i in ("%time%") do (
set /A START_HOUR=%%i
set /A START_MIN=%%j + 2

call :AdjustStartTime


SCHTASKS /Create /SC ONCE /TN "My Scheduled Task Name" /RU "" /TR "C:\Windows\System32\Calc.exe" /ST %START_HOUR%:%START_MIN%


If you don't want to use at, a quick way is to just sleep before your main program.

sleep 10 ; mycommand

Or put that in a script.

  • One of my goals is to execute the command as the LocalSystem user. Your solution doesn't suit my needs. – Jader Dias Feb 8 '11 at 22:16
  • @Jader: That's important information you need to state in the question. – Ben Voigt Feb 19 '11 at 19:24

Patrick S.'s answer met my needs.

I would like to mention however that the quotation marks do not need to be there following the /TR and for whatever reason, seemed to break my script.

Upon removal, his script worked great!

My usage was in an Outlook rule. A script is called and an email is written to the drive with a plugin (messagesave). This is to post to a website from my office PC for a website and my original script that calls the batch needs to terminate prior to a file being written. I had a tough time figuring out how to appropriately delay the scheduled task, even after hitting the 'schtasks' TechNet page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.