views:

401

answers:

1

Alright. So. None of these create the scheduled task correctly with %DATE% and %TIME%:

SCHTASKS /Create /TN MyTask /TR "echo %DATE% %TIME% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo ^%DATE^% ^%TIME^% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo \%DATE\% \%TIME\% >> C:\SchtaskLog.txt" /SC MINUTE SCHTASKS /Create /TN MyTask /TR "echo `%DATE`% `%TIME`% >> C:\SchtaskLog.txt" /SC MINUTE

How does one escape a command-line argument with environment variables to be evaluated later?

A: 

You can get it to work if you wrap the command in a .cmd file. Put this into a .cmd file:

@echo %date% %time%

And then run this cmd:

SCHTASKS /Create /TN MyTask /TR "emittime.cmd >> C:\Log.txt" /SC MINUTE

it does what I think you want.

Cheeso