-1

My robocopy batch script was able to run successfully in the command prompt, but the same bat file failed to run when started from the Task Scheduler. The script was started, but instead of copying the files, robocopy returned a 'Not Enough Memory Resources Error.' The commands run on the command prompt for the script were identical, but the behavior was inexplicably different.

ndw
  • 513
  • 6
  • 14

1 Answers1

0

Robocopy and Windows Task Scheduler have strange unexplained problems interacting with spaces in path names. In the task scheduler, I was providing the full path to the batch script and using the 'start in' option in the Edit Actions settings dialog, which seems to have been the ultimate source of the not enough memory error. In testing, trying to use the full path to the script without the 'start in' options dialog did not work. Additionally, quoting the path name in Edit Action interface caused a 'directory not found error'

Solution for the Edit Action dialog in Task Scheduler:

  • Program/Script should be cmd
  • Edit the Start in (optional) Action settings for the scheduled task to point to the folder with your bat file. This does not need quotes
  • Add the following arguments to Add Arguments (optional) /c start myscript.bat
    • Don't put spaces in the bat script name

Solution for RoboCopy paths with spaces in the name:

  • Do not include trailing backslashes in the path name
  • Use double-quotes to quote any path names in the robocopy command and include a trailing space before the last quote.
    • e.g. robocopy "C:\My Share\My Folder With Spaces " "E:\My Backup " /E...

Other notes:

  • Add an EXIT at the end of your bat file to be sure to close the console window after completing successfully. start and /c does not seem to cause robocopy to close automatically.
ndw
  • 513
  • 6
  • 14