0

I tried to schedule a task by

schtasks /create /tn Test /sc minute /mo 1 /tr "del /f \"%UserProfile%\path\file\""

...however the Scheduler always ends up with the following type of error:

Task Scheduler failed to launch action "del" in instance "{a6c5962d-ed1e-4917-9d43-07525dd03218}" of task "\Test". Additional Data: Error Value: 2147942402

The file in the path exists. I can run the same del command from console and it deletes the file successfully, but I cannot make it work with scheduled task.

What I am doing wrong?

Ωmega
  • 103
  • 1
  • 3

1 Answers1

1
where del
INFO: Could not find files for the given pattern(s).

Use

/TR "\"C:\Windows\System32\cmd.exe\" /C del /f \"%UserProfile%\path\file\""
JosefZ
  • 1,564
  • 1
  • 10
  • 18
  • Děkuji Josefe (Thank you, Josef) – Ωmega Feb 19 '20 at 13:07
  • What I am suppose to do to prevent to show a command prompt window when the scheduler runs the task? Currently it shows and immediately closes the command prompt window, which is unwanted and annoying. Please advise. Thanks. – Ωmega Feb 19 '20 at 14:54
  • [How to prevent command window from appearing on scheduled tasks on Windows 10](https://pureinfotech.com/prevent-command-window-appearing-scheduled-tasks-windows-10/) works however I don't know how to do that using `schtasks.exe` tool without `/XML xmlfile` where `xmlfile` contains `S4U`. – JosefZ Feb 19 '20 at 20:27
  • I was looking for a direct way using command, not through the user interface. – Ωmega Feb 19 '20 at 21:30
  • Please cf [Prevent Windows PowerShell console from flashing up](https://serverfault.com/q/1003763/257436). – JosefZ Feb 20 '20 at 00:30