Why is access denied on moving a folder to program files folder with administrator privileges?

余生长醉 提交于 2019-12-11 10:50:48

问题


So I want to move a folder called test to the directory "%PROGRAMFILES(x86)%". However, even by running the batch file as administrator, it won't really move. I get the error message:

Access denied.

This is my current batch file:

@echo off
move %~dp0test "%PROGRAMFILES(x86)%"
pause

%~dp0 is for the current directory of the folder (desktop in my case).

So how can I solve this issue to move the folder test to "%PROGRAMFILES(x86)%" without the access denied error?


回答1:


The access denied error message could be caused in your case with running the batch file already with administrator privileges by

  • a file in directory to move being currently opened by an application, or
  • the directory to move is the current directory of a running process (batch file), or
  • the administrator account has no permissions on your desktop folder which is very unlikely but possible as it is the folder in your user profile and not in user profile of the administrator account.

In the first two cases it is not possible to delete the specified directory and a sharing access denied error message is the result. So not the permissions in target folder are perhaps the problem here, but the sharing access permissions on source folder and their files.

By the way: Better use move "%~dp0test" "%ProgramFiles(x86)%" as path of batch file could contain a space even if this is not the case currently with batch file being in your Windows desktop folder on Windows Vista or later as long as your user name does not contain a space character.



来源:https://stackoverflow.com/questions/35045149/why-is-access-denied-on-moving-a-folder-to-program-files-folder-with-administrat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!