hdhondt
asked on
COPY command does not work if run as administrator
I have a batch file which I use for my backup. It runs with administrative privileges. It works fine, except for the last command:
This should copy 1 file to a network drive. However, when it tries to execute this, the batch file returns the error "The system cannot find the path specified". If I copy the command line and paste it into a CMD window it runs fine, except if I run CMD as administrator. Conversely, if I do not run the batch file as administrator, the command also executes fine, but then the rest of the batch file fails as it cannot access all files needed.
All other commands in the batch file use ROBOCOPY, and copy to a USB drive, not to a network drive. The network drive is a flash drive that is plugged into my router (TP-Link Archer D5) so it is always visible to other WiFi devices. The PC is hardwired into the router.
Why is it that the same command works if executed as a normal user, but not as administrator?
copy /y "D:\HDDocuments\PWSafe\test.psafe3" n:\
This should copy 1 file to a network drive. However, when it tries to execute this, the batch file returns the error "The system cannot find the path specified". If I copy the command line and paste it into a CMD window it runs fine, except if I run CMD as administrator. Conversely, if I do not run the batch file as administrator, the command also executes fine, but then the rest of the batch file fails as it cannot access all files needed.
All other commands in the batch file use ROBOCOPY, and copy to a USB drive, not to a network drive. The network drive is a flash drive that is plugged into my router (TP-Link Archer D5) so it is always visible to other WiFi devices. The PC is hardwired into the router.
Why is it that the same command works if executed as a normal user, but not as administrator?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't use n:, but use the UNC path that is behind n:
Specify the UNC path.
https://support.microsoft.com/en-us/help/3035277/mapped-drives-are-not-available-from-an-elevated-prompt-when-uac-is-co explains it and offers another way to solve it (set the registry key).
ASKER
Using the UNC path did the trick. Thanks everyone. As Pierre was first he gets the points.