Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to schedule a task to the second with schtasks?

Status
Not open for further replies.

raphael75

Programmer
Nov 15, 2012
67
US
I have a file that creates a scheduled task using schtasks:

<?php
$cur_dt = new DateTime('now');
$cur_dt->add(new DateInterval('PT60S'));
$cmd = 'schtasks /create /sc once /ru uname /rp pwd /tn "repost_labor" /tr "' . $fname . '" /st ' . $cur_dt->format('H:i:s') . ' /sd ' . $cur_dt->format('Y/m/d');

exec($cmd, $out, $retval);
?>

so it generates something that looks like this:

schtasks /create /sc once /ru uname /rp pwd /tn "repost_labor" /tr "myfile.bat" /st 12:52:12 /sd 2013/7/23

However, even though it is trying to set the seconds, Task Scheduler ignores it and only adds the hour & minute. So if the current time is 12:51:12, instead of the above creating a task at 12:52:12, it creates it at 12:52:00.

Why does Task Scheduler ignore the seconds?

Is there a workaround?

Thanks!
 
>Why does Task Scheduler ignore the seconds?

This is the documented behaviour for schtasks

 
Is there a workaround? Maybe a 3rd-party program that can schedule ot the second?
 
I'm afraid it just isn't possible with the built-in scheduler, which is only accurate to the minute (well, there are some tricks you can play with offsets that are originally designed to stop tasks clashing)

To achieve what yo want woul require replacing the built-in scheduler completely. I have no specific recommendations for that.
 
I haven't actually tried this yet, but I think it would be possible to schedule to the second by creating an xml task file and then using:

schtasks /create /xml <filename>

because you can include seconds in the xml.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top