Automate Windows Robocopy with internal changes monitor /MON:1 option

Solution 1:

You may be better off creating a Windows Service for this instead of running it from the task Scheduler. The Service framework is designed around this start-once-run-forever kind of program and has hooks for eventing in case of unknown stoppage.

Creating a user-defined service is pretty easy. Though the article is designed for Windows 2000, it still works for 2008. The 'sc' command is used to create the service.

sc create "Robocopy-Service" binPath= "c:\tools\robocopy.exe" start= auto

Change the values based on how you want the service to run. Once it's there, you can go into the Service Manager and modify the service for how to handle sudden stopping. It'll always record and event ("Service xyz stopped unexpectedly") but you can tell it how to restart the service, or run a script if you need to send emails about it.

Solution 2:

To Expand on the above responses and provide parameters to robocopy:

sc create "Robocopy Service" binpath="c:\windows\system32\robocopy.exe /JOB:robocopy"

This will read the robocopy.rcj file that contains all parameters.

You can execute the robocopy command with all the desired parameters and add the /SAVE:robocopy command to create the robocopy.rcj file. You can then modify the parameters by simply editing the robocopy.rcj file.