14

I need to schedule a Windows task to run a script every minute. In most cases, the script doesn't need to execute anything and exists immediately. When the script needs to execute something, I want it to start the job as quick as possible, thus the one minute interval.

Now, the UI of the Windows Scheduler has become quite confusing in recent years, so I'm not sure what's the best way to run a task every minute (or 5 minutes ..) on Windows 2008 R2.

Is this the best way to schedule a task under Windows every minute? Is it reliable? Does it start directly after a machine is rebooted, or is it only started again at 12pm? Please note that I cannot use/write a custom service application for this, as I need it to be very portable.

1
  • No it is not the best way. You should use a sleep or wait function in your script. Aug 26, 2009 at 15:48

4 Answers 4

4

Yes, this service will run after reboot, you can verify it in the Task Scheduler service transaction log:

    Systemroot\SchedLgU.txt
   
    (where Systemroot is your windows installation folder)

If it's not working correctly (under XP, unsure about 2008 equivalent):

    
    Control Panel -> Administrative Tools -> Services -> Task Scheduler 

    Set to auto. 

2008 Documentation here, XP Documentation here

The task's schedule commences at the specified time, after that it executes based on the repetition parameters. The start time can be considered as "task installation" time, it is not part of the repetition parameters (except as a timer offset). Hope that makes sense!

3
  • I actually meant if the machine is rebooted, is the task triggered again directly after reboot, or is only again started at 12pm, as specified in the GUI? I need the task to run every minute, regardless of a machine reboot etc.
    – Dennis G.
    Aug 26, 2009 at 15:00
  • And, how can I very if a task has been executed? Is it logged somewhere in the Event Log? I cannot seem to find any log entries. Thanks.
    – Dennis G.
    Aug 26, 2009 at 15:03
  • Updated answer for clarification
    – Andy
    Aug 26, 2009 at 15:28
18

I had this same requirement. In Server 2008, you can actually modify the Repeat task every: dropdown. By default the lowest value is "5 minutes", but you can simply type "1 minute" in there. You can verify this by looking at the Triggers tab and seeing that it says "... repeat every 00:01:00...". You can also try typing in "10 seconds" and you'll get an error telling you to choose something greater than 1 minute.

1
  • 3
    This was the part of the question I was interested in. I can confirm this still works in 2012 R2.
    – Melikoth
    Apr 11, 2015 at 19:40
8

I am able to scheduled a task to repeat once per minute with the command line "schtasks". An example of the code is:

schtasks /create /sc minute /mo 1 /tn "Task Name" /tr c:\temp\filename.exe

The task does display in the Windows 2008 R2 GUI and runs once a minute. The task needs to be created and modified with the command line "schtasks" utility.

Unfortunately, Microsoft foolishly designed the Windows 2008 R2 task scheduler, dropping the flexible configuration found in Windows 2003's Task Scheduler, in favor of a few limited choices for intervals.

davephan

1
-1

try this, worked for me...

REM ================================================================

REM # M A I N B O D Y

REM ===============================================================

if "%1" == "" echo Usage:- C:\scripts\port_schtask.cmd ^ ^ && %SystemRoot%\system32\ping 127.0.0.1 -n 10 >nul && exit

if not exist C:\scripts\port.bat echo Usage:- File Does NOT exist C:\scripts\port.bat && %SystemRoot%\system32\ping 127.0.0.1 -n 10 >nul && exit

%SystemRoot%\system32\schtasks /delete /tn "port.bat %1 %2" /f

%SystemRoot%\system32\schtasks /create /tr "C:\scripts\port.bat %1 %2" /SC MINUTE /MO 1 /tn "port.bat %1 %2" /RU "SYSTEM"

%SystemRoot%\system32\SCHTASKS /run /TN "port.bat %1 %2"

%SystemRoot%\system32\SCHTASKS|%SystemRoot%\system32\find.exe "port.bat %1 %2"

%SystemRoot%\system32\schtasks /query /TN "port.bat %1 %2"

%SystemRoot%\system32\ping 127.0.0.1 -n 10 >nul

rem ------------------------------------------------------

cheers RJB

1

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.