Robocopy job will run manually but not as a scheduled task

robocopywindows-server-2012

Using Robocopy on Server 2012.

I have created a .cmd script to copy some files from a mapped drive to the local machine.

The mapped drive is on another server in a different domain and connects with the remote domains domain admin credentials. Domains are not trusted.

It works if i double click the .cmd file and run it manually (logged in as domain admin)

But as soon as it runs as a scheduled task (running also as domain admin) it complete with status code 0 but doesn't actually copy anything.

Simple line from the script:

    @echo on
START /WAIT c:\windows\system32\Robocopy.exe "W:\Folder1\Folder2\Folder3\Folder4" "C:\Folder1\Folder2\Folder3\Folder4" file.txt /np /LOG+:"C:\RCLog\schtask.log"

When run manually the log file contains:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : 13 December 2013 10:51:59
   Source : W:\Folder1\Folder2\Folder3\Folder4\
     Dest : C:\Folder1\Folder2\Folder3\Folder4\

    Files : file.txt

  Options : /DCOPY:DA /COPY:DAT /NP /R:1000000 /W:30 

------------------------------------------------------------------------------

                       1    W:\Folder1\Folder2\Folder3\Folder4

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         0         0         0         0
   Files :         1         0         1         0         0         0
   Bytes :     4.1 k         0     4.1 k         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : 13 December 2013 10:51:59

But when run from the scheduled task:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : 13 December 2013 10:44:47
2013/12/13 10:44:47 ERROR 3 (0x00000003) Getting File System Type of Source W:\Folder1\Folder2\Folder3\Folder4\
The system cannot find the path specified.


   Source - W:\Folder1\Folder2\Folder3\Folder4\
     Dest : C:\Folder1\Folder2\Folder3\Folder4\

    Files : file.txt

  Options : /DCOPY:DA /COPY:DAT /NP /R:1000000 /W:30 

------------------------------------------------------------------------------

2013/12/13 10:44:47 ERROR 3 (0x00000003) Accessing Source Directory W:\Folder1\Folder2\Folder3\Folder4\
The system cannot find the path specified.

Anybody any ideas please?

Thankyou

Best Answer

Just use the UNC path to the remote server instead of drive letter W:

Probable reason is the network mapping isn't available during the scheduled task. You can also change your script to map the drive, do robocopy and unmap it in the end, but it's simpler to use UNC path.