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
> 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 -rOutput
/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?
| Situation | Check | Fix |
|---|---|---|
| Read-only file | attrib file shows R | attrib -r file, or del /f file |
| No NTFS permission | Properties > Security, or icacls file (read only) | get access from the owner or an administrator |
| Needs administrator | the title bar does not say Administrator | Run as administrator |
| Folder instead of file | dir /b /ad | use rd folder, not del |
| File open in another program | message is different | see 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
Related pages
errors · cmdThe process cannot access the file because it is being used by another process.Windows error 32: another program holds the file open without sharing. Find it with Resource Monitor or handle.exe, close it, then retry the del, move or copy.errors · cmdcmd: The system cannot find the path specified.cmd prints The system cannot find the path specified when a folder in the path is missing, a path with spaces is unquoted, or AutoRun names a bad path.cheat sheets · cmdcmd cheat sheet: files, variables, batch syntax and network commandsCommand Prompt cheat sheet: files and folders, variables and substrings, if and for in batch files, plus ipconfig, netstat -ano, tasklist and systeminfo.