问题
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