Reputation: 8502
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?
Upvotes: 0
Views: 2660
Reputation: 11
Try this
SCHTASKS /Create /TN MyTask /TR "cmd /c echo \"^%^date% ^%^TIME%\" >> C:\SchtaskLog.log" /SC MINUTE /F
Upvotes: 1
Reputation: 192437
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.
Upvotes: 0