Bizarre AT scheduling behaviour

  • Thread starter Thread starter Csaba Gabor
  • Start date Start date
C

Csaba Gabor

Here is some Thanksgiving weirdness. Maybe someone has some comments:

If you schedule a task in a simple way with AT (e.g. AT 16:42 cmd "/K
dir"), after it runs, it will delete itself. Now it might be the case
that I want to schedule a task (with AT) and have it run right away.
I could schedule the task for the next minute (e.g. it is 10:03:23 so
I would schedule the task for 10:04. AT and SchTasks granularity is
to the minute, at least on Win XP). But suppose that I am an
impatient type of individual, begrudging those wasted seconds.

In that case, I would do the following:
AT 16:42 cmd "/C" dir => I get back a task id, say 29. And then,
Schtasks /run /tn 29 => task runs immediately. Nifty.

Now here's the bizzaro behaviour. If the task has been scheduled for
less than about 60 seconds from now, it will be automatically deleted
after the second line! Otherwise, the task sticks around and will be
run (again) at the indicated time. If you right click on the tasks
scheduled with AT in the above fashion, it says, "Delete the task if
it is not scheduled to run again." So I would really like to
understand the exact circumstances under which this mysterious
deletion is occurring. Ie. comments are welcome.


Interesting, but not bizarro behaviour: In keeping with the
"Impatient Script" theme... What I actually wanted was for the task to
be deleted after I had forced a run on it with Schtasks. So, after
that Schtasks line, I did:
AT 29 /delete

Of course I did so programmatically with two invocations of
WScript.Shell's Run command. The task never executed! Further
investigation revealed that the first command executed just fine and
SchTasks reported success for the immediate run. Trouble is, by the
time the responsible agency actually got around to running the task,
that following AT command had deleted it. By a sufficient delay (of
half a second!) I was able to execute and then delete the task. But I
don't like arbitrary delays, so what I wound up doing was scheduling
another task to delete the first one, a fitting if not the most
elegant of ends (not elegant because the subsequent task might have to
wait up to a minute to dispatch its victim).

Gobble gobble,
Csaba Gabor from Vienna
 
Csaba Gabor said:
Here is some Thanksgiving weirdness. Maybe someone has some comments:

If you schedule a task in a simple way with AT (e.g. AT 16:42 cmd "/K
dir"), after it runs, it will delete itself. Now it might be the case
that I want to schedule a task (with AT) and have it run right away.
I could schedule the task for the next minute (e.g. it is 10:03:23 so
I would schedule the task for 10:04. AT and SchTasks granularity is
to the minute, at least on Win XP). But suppose that I am an
impatient type of individual, begrudging those wasted seconds.

In that case, I would do the following:
AT 16:42 cmd "/C" dir => I get back a task id, say 29. And then,
Schtasks /run /tn 29 => task runs immediately. Nifty.

Now here's the bizzaro behaviour. If the task has been scheduled for
less than about 60 seconds from now, it will be automatically deleted
after the second line! Otherwise, the task sticks around and will be
run (again) at the indicated time. If you right click on the tasks
scheduled with AT in the above fashion, it says, "Delete the task if
it is not scheduled to run again." So I would really like to
understand the exact circumstances under which this mysterious
deletion is occurring. Ie. comments are welcome.


Interesting, but not bizarro behaviour: In keeping with the
"Impatient Script" theme... What I actually wanted was for the task to
be deleted after I had forced a run on it with Schtasks. So, after
that Schtasks line, I did:
AT 29 /delete

Of course I did so programmatically with two invocations of
WScript.Shell's Run command. The task never executed! Further
investigation revealed that the first command executed just fine and
SchTasks reported success for the immediate run. Trouble is, by the
time the responsible agency actually got around to running the task,
that following AT command had deleted it. By a sufficient delay (of
half a second!) I was able to execute and then delete the task. But I
don't like arbitrary delays, so what I wound up doing was scheduling
another task to delete the first one, a fitting if not the most
elegant of ends (not elegant because the subsequent task might have to
wait up to a minute to dispatch its victim).

Gobble gobble,
Csaba Gabor from Vienna

Schtasks.exe was introduced under WinXP. It is not
native to Win2000. If you're running it under Win2000
and if you try to use it to manage jobs created by at.exe
then you can expect some bizarre behaviour.

Conversely, if you use schtasks.exe on a WinXP PC to
manage tasks generated by at.exe then I would not be
surprised if you got some weird results. Best to use
at.exe to manage tasks generated by at.exe and
schtasks.exe to manage tasks generated by schtasks.exe.
 
Schtasks.exe was introduced under WinXP. It is not
native to Win2000. If you're running it under Win2000
and if you try to use it to manage jobs created by at.exe
then you can expect some bizarre behaviour.

Conversely, if you use schtasks.exe on a WinXP PC to
manage tasks generated by at.exe then I would not be
surprised if you got some weird results. Best to use
at.exe to manage tasks generated by at.exe and
schtasks.exe to manage tasks generated by schtasks.exe.

I'm on Win XP Pro. I believe that a more precise statement of what I
noticed is that if the AT task is run within 1 minute of its scheduled
runtime, then the task is subsequently deleted.

I agree that SchTasks and AT do not mix well. In fact, rather
poorly. And dismally, if talking about programmatic interactions
(such as modifications or access to scheduled tasks). But my first
guess is that that is not the issue here. I haven't tried yet, but I
suspect that the same behaviour will be exhibited if I try to run the
AT task manually from the Scheduled Tasks window. By the way, is
there an AT way to cause a scheduled AT task to be run from the
command line other than through SchTasks?

Csaba
 
Pegasus (MVP) said:
Schtasks.exe was introduced under WinXP. It is not
native to Win2000. If you're running it under Win2000
and if you try to use it to manage jobs created by at.exe
then you can expect some bizarre behaviour.

Conversely, if you use schtasks.exe on a WinXP PC to
manage tasks generated by at.exe then I would not be
surprised if you got some weird results. Best to use
at.exe to manage tasks generated by at.exe and
schtasks.exe to manage tasks generated by schtasks.exe.

Why not simply START the second task?
 
Why not simply START the second task?

If you mean running the scheduled task rather than scheduling it, then
the reason is that (1) The scheduled task will probably run under a
different user name (for example, AT tasks run under SYSTEM).

If you mean having the scheduled task be a run, I don't see what that
gains since the task itself is already executing correctly.

If you mean the 2nd scheduled task (which will delete the first one)
that I refer to in my reply to Pegasus, then I don't see how I can
circumvent that scheduled task via START.

Perhaps you meant something entirely different. It's not clear to me
from your terse post. Perhaps you could elaborate.

Thanks,
Csaba
 
Back
Top