Copying file to UNC path map to local server.

jamar49
jamar49 used Ask the Experts™
on
I have created batch job to copy a file to UNC path, which is mapped to my computer. The batch job run from task scheduler but the file doesn't transfer to UNC path. But if I run command manually is successfully copy files. I have tried both batch below:
####################################
  @echo off
pushd c:\xxx\zzzz\yyyyyy\
COPY * Q:\test\--(note:this is the map drive letter for unc path)
Sleep 5
popd
end
cls
################################################
@echo off
cd c:\xxx\zzzz\yyyyyy\
move * Q:\test\--(note:this is the map drive letter for unc path)
sleep 5
del *
#end
exit



Action Started
Task Scheduler launched action "C:\Windows\SYSTEM32\cmd.exe" in

instance "{90e9b280-15df-4a79-9ec1-6bef9a621423}" of task

"\xxxxxx".

Action completed
Task Scheduler successfully completed task "\xxxxxx" , instance

"{90e9b280-15df-4a79-9ec1-6bef9a621423}" , action "C:\Windows

\SYSTEM32\cmd.exe" with return code 0.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
how is your task setup? is it set to run whether the user is logged on or off? and you entered the users parameters?
If it is set to run with highest level then the mapped drive letter probably doesn't exist in the administrator context.
Try using the fdqn rather than the mapped drive letter ie. \\server\share\directory
kevinhsiehNetwork Engineer

Commented:
Don't use mapped drive letters. Just refer to the UNC path that the Q drive maps to.

Commented:
I would recommend using robocopy to transfer the files, it comes standard with Windows. There are a lot of switches you can include in your batch job to handle a host of scenarios. You can run the batch job as yourself just ensure that you have access to the source and destination paths. From the command line type robocopy /? to see the list of switches. Ensure you set the /r (retry on failure) and /w (wait between retries) switches as this is the most common reason jobs will fail. Typically /r:3 /w:1 will do the trick.
kevinhsiehNetwork Engineer

Commented:
The reason why mapped drives in a scheduled job is unreliable is because mapped drive is not a property of the system, but rather the user session. For example, if you RDP into a server and map a drive, you get that drive mapping. If I am logged into the same server at the same time, I will not get that drive letter mapping. The same thing goes for anything running in a scheduled task.

Now, if your script first mapped the Q drive, then you could use Q drive letter in the rest of the script, but why bother? Just use UNC paths instead.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial