Access to the path '...' is denied
Access to the path '...' is denied
DodaTech
3 min read
The “Access to the path ‘…’ is denied” error means your process lacks permissions to read, write, or delete the specified file or directory.
What It Means
Windows uses a discretionary access control system where every file and folder has an ACL (access control list) specifying which users and groups can perform which actions. PowerShell runs under your user account’s security context. When your account does not have the required permission — or the file is locked by another process — the operating system denies the operation and PowerShell surfaces the .NET UnauthorizedAccessException.
Why It Happens
- You do not have read or write permissions for the target file or folder.
- The file is marked read-only or is a system file.
- Another process (antivirus, another PowerShell window, a text editor) has the file locked.
- PowerShell is not running with administrator privileges and the path is protected (e.g.,
C:\Windows\System32). - The file attributes include
HiddenorSystem, and your script does not handle them. - The file is encrypted with EFS and your user does not have the decryption key.
How to Fix It
1. Run PowerShell as Administrator
# Right-click PowerShell and select "Run as administrator"
# Or from an existing admin session:
Start-Process powershell -Verb RunAs2. Check and modify file permissions
# Check current permissions
Get-Acl -Path "C:\Protected\file.txt" | Format-List
# Grant full access to your user (run as admin)
$acl = Get-Acl "C:\Protected\file.txt"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
"$env:USERDOMAIN\$env:USERNAME",
"FullControl",
"Allow"
)
$acl.SetAccessRule($accessRule)
Set-Acl -Path "C:\Protected\file.txt" -AclObject $acl3. Remove read-only attribute
Set-ItemProperty -Path "C:\Path\to\file.txt" -Name IsReadOnly -Value $false4. Unlock the file by closing the holding process
# Find which process has the file locked
# Use Sysinternals Handle or:
Get-Process | Where-Object {
$_.Modules.FileName -match "filename"
}5. Take ownership of the file
# Run as Administrator
takeown /F "C:\Protected\file.txt"
icacls "C:\Protected\file.txt" /grant "$env:USERNAME`:F"6. Bypass inaccessible directories with error handling
Get-ChildItem -Path "C:\Windows" -Recurse -ErrorAction SilentlyContinueBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro