Skip to content

/errors/cmd/access-is-denied

cmd: Access is denied.

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Command Prompt (cmd)
exit code
5
versions
Windows 10, Windows 11, Windows Server 2016+
os
windows

Access is denied. is Windows system error 5 (ERROR_ACCESS_DENIED). The file or folder exists, but the operation is not allowed for the current process: the file is read-only, your account lacks NTFS permissions, or the command needs an elevated (Run as administrator) Command Prompt. For a read-only file, attrib -r file or del /f file is the fix.

Reproduce it with a read-only file

cmd
> notes.txt echo keep me
attrib +r notes.txt
del notes.txt 2>&1
echo del: ERRORLEVEL=%ERRORLEVEL%
attrib -r notes.txt
del notes.txt
if not exist notes.txt echo deleted after attrib -r

Output

/tmp/work/notes.txt
Access is denied.
del: ERRORLEVEL=0
deleted after attrib -r

del prints the full path of the file and then Access is denied., but ERRORLEVEL stays 0, so a batch file cannot rely on del's exit code; test the result with if exist instead.

Which case is it?

SituationCheckFix
Read-only fileattrib file shows Rattrib -r file, or del /f file
No NTFS permissionProperties > Security, or icacls file (read only)get access from the owner or an administrator
Needs administratorthe title bar does not say AdministratorRun as administrator
Folder instead of filedir /b /aduse rd folder, not del
File open in another programmessage is differentsee the process cannot access the file

net commands that need elevation, such as net session, print System error 5 has occurred. followed by Access is denied. when run from a normal window.

Sources