user2303184
user2303184

Reputation: 11

AT to SCHTASKS: how to avoid repetition?

I'm adapting a WinXP batch file that used the AT command to schedule some interactive, fairly-long-duration, activities (and later to kill the processes they would spawn) to use Win7's version of SCHTASKS (since AT in Win7 no longer supports the /interactive flag), e.g. translating

at 00:59 /interactive /every:Monday "h:\bin\scrape.bat"

at 03:02 /interactive /every:Monday "h:\bin\kill_scrape.bat"

to something like:

schtasks /Create /TN SCRAPER /IT /ST 00:59 /K /ET 03:02 /ST: 04:02\

              /SC WEEKLY /D MON /TR "h:\bin\scrape.bat"

...which would seem to be simpler, as it would use the scheduler directly to kill the scheduled activity (if I am right in understanding how /K works with /ET or /DU. The above works, but the task repeats with the default interval of 10 minutes. With the /RI option I could give this a repetition interval of up to 122 minutes...but it then could still repeat at the {one hundred and twenty-second}-minute, I gather, and I don't want that...and there are many lines to translate, and my elisp isn't good enough to subtract one minute from all the task durations anyway. Is there any option in SCHTASKS to avoid any repetition of the scheduled task? Thanks very much.

Upvotes: 1

Views: 1416

Answers (2)

DudeTrollingForums
DudeTrollingForums

Reputation: 11

use /RI 0 to disable repeat task

Upvotes: -1

Evan
Evan

Reputation: 594

I believe what you need is a schedule option (/SC). Valid timed options are daily, weekly monthly, 'minute', 'hourly', with obvious effects.

If you're looking to run the task exactly once, across all time, /SC once will do the trick. Adding the /Z option will delete the task for you too.

If none of those options fit your needs precisely, you should be able to use the /RI (run interval) switch to set the exact number of minutes you want the task to repeat after. I'm not sure what the maximum interval is on XP but it should be at least a day, and the maximum on windows 7 is 599940 minutes, or 416 days.

An example of what you would want is this:

schtasks /Create /TN SCRAPER /IT /ST 01:00 /ET 03:01 /K /SC WEEKLY /D MON /TR "h:\bin\scrape.bat"
schtasks /Create /TN ender /IT /ST 3:00 /K /SC WEEKLY /D MON /TR "h:\bin\end.bat"

Where scrape.bat is the initial program and end.bat kills all the processes.

Upvotes: 0

Related Questions