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.

5 Answers5

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?

Dave
  • 614
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.

Col
  • 7,043
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

Well, I use that dumb method:

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

kokbira
  • 5,429