2

*nix has the "at" command, which can be piped to to run a program at a certain time. Like this:

echo "SOME_COMMAND" | at 00:00

Windows also has an "at" command, which creates a run-once scheduled task that runs in the background by the user SYSTEM. "schedtasks" is more complete, but also a pain to use (especially since it requires a unique name for each task, the idea of creating a batch to create a run-once task *nix style in order to mimic *nix's "at" becomes kinda unpractical).

So, is there a utility for Windows that does what *nix's "at" does, in a simple, non-hassle way?

UPDATE: I'll be more a little more specific now =). I'm trying to power off my monitor at a certain time, and I use a command-line utility called nircmd so I can simply type "nircmd monitor off" to do the job. If I used Linux on this computer, all I had to do was

echo "nircmd monitor off" | at XX:YY

or create a "macro". But in Windows I only have the scheduled tasks, which is a rather bureaucratic way of creating a run-once task, since "at" doesn't really work (see my similar question Windows Task Scheduler and possible permission problems) and "schedtasks" requires the whole unique name thing mentioned above.

Being a programmer, it should be easy enough to create such a program that mimics Unix's "at". But I wanted to make sure that I wasn't reinventing the wheel first.

3
  • Not really. If you want simplicity, you're stuck with at. If you want complexity, you're stuck with schedtasks. It's unfortunate, but that's the case. There may be a third party tool out there to make it easier, or you could just write a batch script to do it.
    – nhinkle
    Jul 14, 2010 at 7:16
  • I guess I should have made it clearer before: I have no hopes of finding such a tool in Windows itself, so what I'm really looking for is a third-party tool. Jul 14, 2010 at 13:46
  • I that after reading your update you will probably come to the same conclusion that I have done and just write your own simple scheduler, it is fairly simple to write a program in your preferred language which runs in the background and intermittently checks whether it's X o'clock yet and if so to run task Y. Jul 15, 2010 at 5:29

5 Answers 5

3

So here's how I managed to solve the problem. I created a .bat file called killscreenat.bat and put it into /Windows/system32 (but you can obviously put it anywhere - or anywhere that's in your PATH, for that matter). The script is simple:

schtasks.exe /create /SC ONCE /TN poweroffmonitor /TR "nircmd monitor off" /ST %1 /F

And the usage is simple:

killscreenat HH:MM

The key was the (heavily un/misdocumented) /F option. While it doesn't say so in Technet's doc (or any other place I read), it forces Scheduled Tasks to overwrite the created task if it already exists.

It's not a global solution - meaning you can't just "pipe" any command to it, but if your "task" is frequent like mine, the process is easy enough.

Thanks everyone for the answers, they were really helpful in finding the final solution!

2

Have you tried CygWin a bash shell within windows?

1
  • 1
    Just downloaded that, and while it doesn't override Windows's commands (so, no Unix's "at"), it's still a GREAT thing to have installed. Thanks! Jul 15, 2010 at 16:13
1

There are various flags on the at command in windows which will let you set up repeating and interactive tasks, just do at --help for the full list. To me it looks like you're after a combination of /every: and /interactive but I'm not sure what exactly you're trying to achieve.

1
  • The /Interactive option is disabled in windows 7 due to a security upgrade (or rather a downgrade due to security issues).
    – tovare
    Jul 14, 2010 at 11:19
1

Scheduled tasks on Windows desktop machines (not server editions, these seem ok-ish) are in my experience completely unreliable and still don't work on Windows 7. You will find that you create tasks that work for a while and then suddenly don't for no reason that you can determine.

You will probably run into permission problems of some kind with AT if you are trying to use it on Windows Vista/Windows 7 as you need to run an elevated command prompt to even access the command.

What are you trying to achieve, it might be possible that you could roll your own scheduler or use another third-party tool instead?

1
  • Please see update above, I clarified some things. Jul 14, 2010 at 13:47
1

Well, I use that dumb method:

:label1
if "%time%" GTR "15:00:00,00" do (
put your commands here
goto label2
)
goto label1
:label2

1
  • 1
    Seems a bit of an "ugly" workaround for me, but should work when all else fails =) Jul 15, 2010 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .