Error 5 in Command Prompt—often labeled "Access Denied"—means you’re trying to run a command without sufficient permissions. This isn’t a command itself, but a system-level error code (0x5) that blocks operations like installing software, deleting files, or modifying system files. The fix depends on whether you need elevated permissions and whether the issue is with the user account or the file itself. Here’s how to resolve it immediately, step by step.

What You'll Need

  • A PC running Windows 10 or 11 (most common for this issue).
  • Admin rights—either on your user account or via another admin account.
  • An open Command Prompt window (right-click > "Run as administrator").
  • The specific command or file you’re trying to access (some examples below).

Step-by-Step

  1. Restart your PC. Sometimes the most straightforward solution is to reboot. Close all open programs, then hold the Shift key while clicking the Start menu to restart in Safe Mode with Networking (if the issue persists). If you’re in Safe Mode, try again normally.
  2. Run Command Prompt as Administrator. Open the search bar, type cmd, right-click Command Prompt, and select Run as administrator. If you get prompted by the UAC (User Account Control) prompt, click Yes. If this doesn’t work, try using powershell instead: Search for "PowerShell," right-click, and select Run as administrator.
  3. Use the netsh or icacls command to check/adjust permissions (for files or folders). If you’re trying to modify a file or folder, navigate to its location in File Explorer and right-click > Properties. Go to the Security tab and click Edit. Ensure your user account or an admin account has Full Control—if not, click Add, type your username, and check the box for Full Control. Click OK three times.
  4. Alternatively, in Command Prompt (as admin): Navigate to the folder using cd path\to\folder, then run: icacls "C:\path\to\file" /grant YourUser:(OI)(CI)F (Replace YourUser with your username and the path to the file/folder.) If you get an error like Insufficient access rights, restart your PC with an admin account or use another method below.
  5. Take ownership of the file or folder. If permissions are locked (e.g., by another user), right-click the file/folder > Properties > Security > Advanced. Click Take Ownership. If blocked, click Change link target and navigate to your profile folder (C:\Users\YourUser). Click OK, then try taking ownership again.
  6. Use the takeown and icacls commands in Command Prompt. As admin, navigate to the folder and run: takeown /f "C:\path\to\file" /r /d y Then grant permissions: icacls "C:\path\to\file" /grant YourUser:(OI)(CI)F (Repeat for child folders if needed.)
  7. Reinstall the software or driver causing the issue. If the error occurs when installing an app or driver, uninstall it via Settings > Apps > Installed Apps and reinstall. For drivers, use Windows Update or the manufacturer’s website. For system files, use DISM /Online /Cleanup-Image /RestoreHealth or SFC /scannow in an elevated Command Prompt.
  8. Create a new admin account (last resort). If your user account lacks permissions, create a new admin account: 1. Press Win + X > Settings > Accounts. 2. Click Family & other users > Add someone else to this PC. 3. Enter a Microsoft account or sign in as a local admin (if available). 4. Use this new account to access files/folders.

Common Mistakes

  • Ignoring UAC prompts. Always click Yes when prompted for admin rights—UAC is designed to prevent errors like this. If UAC is disabled, enable it via Settings > Accounts > Family & other users > Manage another account > Change account type and select Administrator.
  • Forgetting to run commands as admin. Non-admin users cannot execute most system commands (e.g., netsh, icacls) without elevation. Always open Command Prompt/PowerShell as admin first.
  • Modifying the wrong files. Some system files (e.g., C:\Windows\System32) require admin rights for changes. If you modify the wrong folder, you may need to reinstall software or use system repair tools.
  • Using incorrect permissions. Overwriting permissions (e.g., giving Everyone access) can break the system. Always grant your user account full control or the minimal required rights.
  • Skipping the restart. Changes to permissions or ownership may not apply until you log out and back in or restart. If the error persists, do both.

Tips

  • Use PowerShell for advanced tasks. PowerShell often has more flexible commands than Command Prompt. Try: New-Item -Path "C:\path\to\folder" -ItemType Directory -Force (Replaces older mkdir with better error handling.)
  • Check the exact file path. Right-click the file in File Explorer and select Properties > Details to verify the path before running commands. A typo can lead to "Access Denied" for the wrong folder.
  • Avoid third-party tools. Tools like "Ownership Changer" may not apply permissions correctly. Stick to built-in Windows commands for reliability.
  • Use takeown and icacls together. These commands work for file/folder ownership and permissions simultaneously, reducing steps. For example: takeown /f "C:\file.txt" /r then icacls "C:\file.txt" /grant YourUser:(OI)(CI)F
  • Enable "Show hidden files." Some system files are hidden. In File Explorer, go to View > Hidden items to spot locked files.

Troubleshooting

If none of the above steps work, try these next:

  1. Check for malware. Run a scan with Windows Defender or third-party tools like Malwarebytes. Malware can lock files or modify permissions. If infected, use Windows Recovery or a clean boot to fix permissions.
  2. Reset file permissions via Command Prompt. Navigate to the folder and run: icacls "C:\path\to\folder" /reset (Replace the path.) This resets permissions to default but may require reapplying your user’s access.
  3. Use a system repair tool. If the issue persists after basic fixes, use: DISM /Online /Cleanup-Image /RestoreHealth followed by SFC /scannow in an elevated Command Prompt. Restart afterward.
  4. Restore from a system image or backup. If permissions are corrupted across the system, create a restore point or use a Windows backup. In Command Prompt, run: restore and follow prompts. For system images, use DISM or Recovery options in Windows.
  5. Reinstall Windows (last resort). If all else fails, back up data and reinstall Windows. This resets permissions and user accounts to factory settings.

Frequently Asked Questions

Why does "Access Denied" appear when I try to delete a file?

The file is likely locked by another process (e.g., antivirus, a running program, or a scheduled task). Close all applications, wait 30 seconds, and try again. If the file is owned by another user, use takeown or a new admin account to take ownership before deletion.

How can I fix "Access Denied" when updating a driver?

Uninstall the driver via Device Manager > Driver tab > Uninstall device, then restart. Let Windows reinstall it. If the error persists, use the manufacturer’s website to download the latest driver, install it manually as admin, and restart.

My Command Prompt still says "Access Denied" after restarting. What’s wrong?

The issue may be with a locked folder or system file. Run icacls "C:\Windows" /grant Administrator:(OI)(CI)F (replace "Administrator" with your username if needed) to grant full access. If the folder is read-only, enable editing in File Explorer by right-clicking > Properties > General > Uncheck "Read-only."

Can I fix permissions without admin rights?

No. Non-admin users cannot modify system files or folders. You must use an admin account or a new admin user account to apply changes.

Why does running a command as admin fix some errors but not others?

Some errors occur because the command targets system files (e.g., C:\Windows\System32) or requires elevated permissions. Others (like deleting a user file) can be fixed with ownership changes. Always check the exact command and file path before running.

How do I fix "Access Denied" when installing Windows Update?

If the error happens during updates, boot into Safe Mode (hold Shift while clicking Restart) and run: SFC /scannow and DISM /Online /Cleanup-Image /RestoreHealth in an elevated Command Prompt. If the issue persists, use Windows Update Cleanup Tool from Microsoft’s website.

If the problem occurs with a specific app, ensure it’s compatible with your Windows version and has the latest updates. Some apps (e.g., game mods) may require manual permissions adjustments via icacls or taking ownership.