Reputation: 25378
The postbuild task for one of our solutions uses xcopy to move files into a common directory for build artifacts. For some reason, on my computer (and on a VM I tested), the xcopy fails with "Access Denied". Here's what I've done to try and isolate the problems:
What have I missed, other than paranoid conspiracy theories involving computers out to get me? This happens on my dev machine and a clean VM, but doesn't happen for anyone else on the project.
Upvotes: 23
Views: 111627
Reputation: 9614
if you are copying file to IIS folder, then you need run the batch file as admin.
Upvotes: 0
Reputation: 151
You need to run XCOPY as Administrator, there is no way around this.
If you don't want to run your copy as Administrator, then you must use ROBOCOPY instead.
Note, however, that with ROBOCOPY it is very tempting to use the /COPYALL
switch, which copies auditing info as well and requires "Manage Auditing user right", which again invites you to run as Administrator as a quick solution. If you don't want to run your copy as Administrator, then don't use the /COPYALL
(or /Copy:DATSOU
) switch. Instead use /Copy:DATSO
, as the U stands for aUditing.
Also note that if you are copying from NTFS to a FAT files system, there is no way you can "Copy NTFS Security to Destination Directory/File".
Upvotes: 6
Reputation: 3901
/r = Use this option to overwrite read-only files in destination. If you don't use this option when you want to overwrite a read-only file in destination, you'll be prompted with an "Access denied" message and the xcopy command will stop running.
That's was mine resolution to this error.
Upvotes: 27
Reputation: 8424
If you can delete the file in Windows Explorer, try using an elevated command prompt. Not sure why Windows Explorer does not ask permission here for a delete operation that needs admin rights via cmd.
Upvotes: 0
Reputation: 25378
Problem solved; there's two pieces to the puzzle.
The /O switch requires elevation on Vista. Also, I noticed that xcopy is deprecated in Vista in favor of robocopy. Now I'm talking with our build engineers about this.
Upvotes: 18
Reputation: 77101
Usually this happens because there's another process locking the file. I bet your machine has a different number of cores/different speed than the others. Try inserting some sleeps to see if it solves the problem.
Upvotes: 1