windows 是什么导致 xcopy 告诉我访问被拒绝?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/659463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's causing xcopy to tell me Access Denied?
提问by OwenP
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:
我们的解决方案之一的后期构建任务使用 xcopy 将文件移动到构建工件的公共目录中。出于某种原因,在我的计算机(以及我测试的 VM)上,xcopy 失败并显示“拒绝访问”。这是我为尝试隔离问题所做的工作:
- I tried a normal copy; this works.
- I double-checked that none of the files in question were read-only.
- I checked the permissions on both the source and destination folder; I have full control of both.
- I tried calling the xcopy from the command line in case the VS build process had locked the file.
- I used Unlocker and Process Explorer to determine there were no locks on the source file.
- 我试过普通副本;这有效。
- 我仔细检查了有问题的文件都不是只读的。
- 我检查了源文件夹和目标文件夹的权限;我对两者都有完全的控制权。
- 我尝试从命令行调用 xcopy,以防 VS 构建过程锁定文件。
- 我使用 Unlocker 和 Process Explorer 来确定源文件上没有锁定。
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'thappen for anyone else on the project.
除了涉及计算机的偏执阴谋论之外,我还错过了什么?这发生在我的开发机器和干净的 VM 上,但不会发生在项目中的其他人身上。
采纳答案by OwenP
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.
/O 开关需要在 Vista 上提升。另外,我注意到 xcopy 在 Vista 中已被弃用,而支持 robocopy。现在我正在与我们的构建工程师讨论这个问题。
回答by Tamir
/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.
/r = 使用此选项覆盖目标中的只读文件。如果您想覆盖目标中的只读文件时不使用此选项,系统将提示您“拒绝访问”消息,并且 xcopy 命令将停止运行。
That's was mine resolution to this error.
这是我对这个错误的解决方案。
回答by iNoob
You need to run XCOPY as Administrator, there is no way around this.
您需要以管理员身份运行 XCOPY,这是没有办法解决的。
If you don't want to run your copy as Administrator, then you must use ROBOCOPYinstead.
如果您不想以管理员身份运行副本,则必须改用ROBOCOPY。
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 usethe /COPYALL
(or /Copy:DATSOU
) switch. Instead use /Copy:DATSO
, as the U stands for aUditing.
但是请注意,使用 ROBOCOPY 时很容易使用/COPYALL
开关,它也复制审计信息并需要“管理审计用户权限”,这再次邀请您以管理员身份运行作为快速解决方案。如果你不想运行副本管理员,那么不使用的/COPYALL
(或 /Copy:DATSOU
)开关。而是使用/Copy:DATSO
,因为 U 代表审计。
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".
另请注意,如果您要从 NTFS 复制到 FAT 文件系统,则无法“将 NTFS 安全复制到目标目录/文件”。
回答by krosenvold
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.
通常发生这种情况是因为有另一个进程锁定了文件。我敢打赌,您的机器与其他机器的内核数/速度不同。尝试插入一些睡眠,看看是否能解决问题。
回答by sennett
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.
如果您可以在 Windows 资源管理器中删除该文件,请尝试使用提升的命令提示符。不知道为什么 Windows 资源管理器不会在此处请求通过 cmd 需要管理员权限的删除操作的权限。
回答by Alper Ebicoglu
if you are copying file to IIS folder, then you need run the batch file as admin.
如果要将文件复制到 IIS 文件夹,则需要以管理员身份运行批处理文件。