1

I need some help setting up a batch file in Windows 7. I want the batch file to be able to create a scheduled task that would execute 1 hour from the moment I click it. I don't want to manually have to put the date and time in, just want it to schedule a task that will execute a set number of hours after I have run the batch file (I'm using 1 as an example).

Please can somebody help me out. I've been searching for an answer all day to no avail.

Mark
  • 3,609
  • 1
  • 22
  • 33
  • try looking for a `Windows` version of [cron](https://en.wikipedia.org/wiki/Cron) also, take a look [here](http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron) – Alexej Magura Jul 30 '13 at 19:40

2 Answers2

1

Recent versions of Windows come with a DOS utility called WAITFOR. Depending on how interactive you want your batch file, and whether it should run a single static command or run whatever you need at the time, you could easily make it work. Like for instance, you could create a batch file on your desktop and drag a program to it and drop it on the batch file. The first thing it would do is prompt for the number of minutes to delay, then it could run the program you dropped on it.

@echo off
setlocal enabledelayedexpansion
set /p _min=Enter the minutes to delay: 
set /a _min*=60
waitfor /t !_min! delay
start "" %1
setlocal

Using the start command makes it possible to drop other things too, like a BMP or Word DOC. Anything that you can launch by double-clicking it from Windows Explorer should launch just fine.

After you enter the minutes to delay, just minimize the DOS window. It will close automatically after the delay and after it launches the program or file you dropped on the batch file.

James L.
  • 9,384
  • 5
  • 38
  • 77
0

invoke windows task scheduler directly from command line

schtasks /create /TN "Task Name" /TR script.bat /ST 18:00 /SD 21/03/2014 /SC ONCE

curtis
  • 11
  • 2