Command Prompt is the default command line tool on Windows that you can use to perform different tasks. Users especially use it to run various command line programs, whether built-in or otherwise.
However, sometimes while running such programs or modifying/deleting a file/folder with this tool, you may encounter the “Access is denied” error message. It may show an error code or tell you the reason for the issue, but usually, it doesn’t provide additional information.
In this article, we have listed all possible causes for the issue along with their corresponding solutions.
Table of Contents
Causes for Command Prompt Access Denied
Here are the potential causes for the Access is Denied error on Command Prompt:
- Lack of admin privilege.
- Misconfigured permissions.
- Encryption of folders and files.
- Malware infection.
- Restriction due to third-party security software.
How to Fix Command Prompt Access Denied?
Below mentioned are the possible solutions to resolve the access error on Command Prompt:
Open Command Prompt as Admin
While the usual Command Prompt is enough for most purposes, you can’t run certain looks, like SFC, DISM, etc., using the program. To do so, you need to run Command Prompt as admin, which elevates its permission level.
You can use either of these methods to open Command Prompt as admin:
- Open Run by pressing Win + R, type
cmd, and press Ctrl + Shift + Enter.
- Search for
command prompton the search bar (Win + S), right-click on it, and select Run as administrator.
- (In Windows 11) Press Win + X, select Windows Terminal (Admin), and press Ctrl + Shift + 2.
Look for and Close the Program Locking the File
You won’t be able to modify or delete files that some other program is using at that moment. If you try doing so, you’ll get the above error message. You can usually close the program by searching for it on the Task Manager or Process Explorer to resolve this issue.
If you know which process or app is responsible, you can use Task Manager.
- Press Ctrl + Shift + Esc to open the Task Manager.
- Search for the app under the Processes tab and right-click on it.
- Select End task.
If you don’t know the process, it’s better to use Process Explorer.
- Download the Process Explorer from Microsoft’s platform.
- Extract the archive and open the program depending on your system architecture.
- Press Ctrl + Shift + F to search for the handle.
- Type the file, folder, or handle due to which you are experiencing this error and press Enter.
- Then, check the list to determine the process involved.
- Close the search box and look for the process.
- Right-click on it and select Kill Process or Kill Process Tree.
However, there may be other possible reasons for the file to be locked. We recommend you refer to our article, File is Open in Another Program to find the necessary solutions for all cases of this issue.
Change Permissions of Current Working Directory (CWD)
Windows uses the NTFS partition, which includes two different types of permissions. One of those is the Access Control List (ACL) which specifies users and groups permissions for a folder/file.
You can also experience this error if you don’t have ownership of the current working directory (the directory you see before the ‘>’ sign) or the file, as well as ACL permissions to read/write inside the directory. It can even happen for system folders like System32 if a malware changes the ACL permissions.
Here’s how you can manually change these permissions and resolve the issue:
- Open the File Explorer (Win + E) and navigate to the directory.
- Right-click on the folder and select Properties.
- Go to the Security tab and click on Advanced.
- Select Change next to Owner.
- Click on Advanced and then Find Now.
- Select Administrators or your user account from the list and click OK > OK.
- Click on Apply.
- Then, check Replace all child object permission entries with inheritable permission entries from this object.
- Select Add under the Permissions tab.
- Click Select a principal and follow steps 4-6.
- Check Full control and click OK.
- Add your user account as a principal if it is not an admin account using the same process. Also, make sure to check Full control for that as well.
- Keep clicking OK to close Properties while saving the changes.
You can also use the Command line for this purpose if you find it daunting to navigate the graphical interface. To do so,
- Sign in to an administrator account.
- Open Command Prompt as Admin.
- Enter the following commands while replacing “Path of file or folder” to the path you need:
takeown /f “Path of file or folder”
icacls “Path of file or folder” /Grant Administrators:f
Scan with Antivirus
As we mentioned earlier, some malware scripts can modify the ACL permissions of your files and folders, leading to this error. You can resolve the issue by manually changing the permissions. However, you also need to detect and remove the malware to prevent such issues from occurring again. To do so,
- Open Run.
ms-settings:windowsdefenderto open Windows Security.
- Go to Virus & threat protection and click on Scan options.
- Check Full scan and select Scan now.
If a file is encrypted, you won’t be able to access it if you don’t have the necessary certificate keys stored on your user account. In such cases, trying to move or modify the file through the Command Prompt displays “Access is denied.” You need to remove the encryption to perform those tasks. To do so,
- Navigate to the file/folder on File Explorer.
- Check if the icons have a lock sign, which signifies that they are encrypted.
- If they have the sign, right-click on the folder/file or the root folder and select Properties.
- Click Advanced on the General tab.
- Uncheck Encrypt Content to Secure Data and click OK > OK.
- Check Apply changes to this folder, subfolders, and files and click OK.
Check File Corruption
It is also possible that your files or folders are corrupted, and your system is protecting itself by denying access. If your CWD is a system directory, you can run the System File Checker (SFC) and Deployment Image Servicing and Management (DISM) to repair such corruption. To do so,
- Open the Elevated Command Prompt (Prompt as Admin).
- Enter the following commands:
dism /online /cleanup-image /restorehealth
Uninstall Third-Party Security Software
It is also possible that some security software like a personal firewall or antivirus is blocking access to a third-party executable file. In such a situation, you will get the Access denied error while trying to run this program.
First, ensure the file is not harmful in any way. Then, you can temporarily disable your third-party firewall or antivirus before using the Command Prompt to run the file. After you are done, don’t forget to re-enable your security apps.
Clean Install OS
If you are unable to resolve the issue after performing all these steps, your only remaining option is to make a clean install of Windows. Below mentioned are the steps to do so. However, depending on your Windows version, there might be a few minor differences.
- First, create a Windows bootable or installation USB.
- Then, restart your PC while keeping the installation USB connected to the device.
- Get to your BIOS using the BIOS key or any other method. You can check official sources to know the BIOS key for your motherboard.
- There go to Boot Priority or Order setting and make sure USB is at the top of the list. You should be able to see the instructions to do so on the BIOS interface.
- Save the changes and exit the BIOS.
- Now, boot using the USB media, set your language preferences, and click Next.
- Select Install now on the Install screen.
- Click on I don’t have a product key, accept the license agreements and click Next.
- Pick your OS version and then click Custom: Install Windows only (advanced).
- Select your system partition and click on Next.
- Follow the on-screen instructions.