1

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

5

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.

  • Had this problem, and this was the solution. Thank you. – rjkunde May 11 '20 at 5:54
2

When the job is run from scheduler, given credentials are used only for authentication, not for recreating whole user's environment. You must copy directly to UNC path or map S: drive to UNC within the script prior to robocopy command.

Going to your issue, in the script , before the ROBOCOPY command add net use w: \netshare_path$. If the script will find the letter w used by a mapped drive will error but continue with ROBOCOPY. If the letter w is not used will map the drive to it and use it in the ROBOCOPY. If you don't need the mapped drive just put in the script the net use w: /delete after ROBOCOPY.

So it should look like this:

NET USE W: \\server\drive_letter$ /USER: <USERNAME> <PASSWORD>
ROBOCOPY "W:\Folder1\Folder2\Folder3\Folder4 " "C:\Folder1\Folder2\Folder3\Folder4 " file.txt /np /LOG+:"C:\RCLog\schtask.log" 
NET USE W: /delete 
-3

For Winrobo copy use the UNC path for the remote server.

URL = http://www.upway2late.com/projects/winrobocopy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.