Fixed: DiskPart Access Denied Error
In this article
To fix the "Diskpart has encountered an error: Access is denied" error, you must run DiskPart as an administrator, because the command requires elevated privileges to modify disk structures. If you already ran it as administrator and still see the error, the target disk is likely protected by the read-only attribute, which you can clear with the attributes disk clear readonly command.
What Causes the Access Denied Error in DiskPart
DiskPart is a Windows command-line utility for managing disks, partitions, and volumes. The "Access is denied" error typically appears when you try to perform an operation that requires higher privileges than your current command prompt has. This includes actions like cleaning a disk, creating a partition, or assigning a drive letter. The error can also occur when the disk itself is write-protected, either by a physical switch on an external drive, a software read-only attribute, or a group policy that restricts disk management.
How to Run DiskPart as Administrator
The most common fix is to launch DiskPart with elevated rights. Here’s how:
- Click the Start button and type
cmdordiskpartin the search box. - Right-click Command Prompt (or DiskPart) and select Run as administrator.
- If prompted by User Account Control (UAC), click Yes.
- Now type
diskpartand press Enter. The prompt should showDISKPART>.
If you’re using Windows PowerShell, right-click the PowerShell icon and choose Run as administrator as well. Running as administrator grants the tool the necessary permissions to access and modify disk structures.
Clearing the Read-Only Attribute
If you’re already running as administrator and still get the error, the disk might have the read-only attribute set. To check and clear it:
- Open DiskPart as administrator.
- Type
list diskand press Enter. - Identify the disk number that corresponds to the problematic disk (e.g., Disk 1).
- Type
select disk 1(replace 1 with the actual number) and press Enter. - Type
attributes diskto view the current attributes. If it says Current Read-only State: Yes, proceed. - Type
attributes disk clear readonlyand press Enter. - Type
exitto close DiskPart, then retry your operation.
Note that some USB drives have a physical write-protect switch. Make sure it’s not in the locked position. Also, certain enterprise or managed devices may enforce read-only policies that can’t be overridden by this command.
Other Common Causes and Fixes
DiskPart on a System or Boot Partition
DiskPart may refuse to modify the system or boot partition (the partition where Windows is installed) while the OS is running. If you’re trying to clean or format the system drive, you’ll need to boot from a Windows installation USB and use DiskPart from the recovery environment (Shift+F10 opens Command Prompt).
Unsupported File System or Partition Type
If you’re trying to format a disk with a file system that isn’t supported (e.g., formatting a GPT disk as MBR without converting), DiskPart may throw an error. Use the convert gpt or convert mbr command after cleaning the disk, but be aware that this erases all data.
Permission Issues on the Disk Itself
Sometimes the disk is locked by another process, like a backup tool or a virtual disk service. Close any programs that might be using the disk and try again. You can also use diskpart’s clean command after selecting the disk, but this removes all partitions and data—use it with caution.
Step-by-Step: Clean and Format a Disk Using DiskPart
If you’ve resolved the access denied error and want to completely wipe a disk, here’s the standard procedure:
- Run DiskPart as administrator.
- Type
list diskto see all disks. - Type
select disk X(replace X with the disk number). - Type
cleanto remove all partitions and data. - Type
convert mbrorconvert gptdepending on your needs. - Type
create partition primary. - Type
format fs=ntfs quick(orfs=exfatfor external drives). - Type
assign letter=E(choose an available letter). - Type
exit.
Remember: clean permanently deletes all data on the selected disk. Double-check that you’ve selected the correct disk before running it.
Alternatives to DiskPart
If DiskPart continues to give you trouble, you can use Windows’ built-in Disk Management (diskmgmt.msc) for basic tasks like formatting and assigning drive letters. For more advanced operations, third-party tools like GParted or AOMEI Partition Assistant offer graphical interfaces and can sometimes bypass permission issues that DiskPart encounters. However, these tools also require administrative rights and should be used with the same caution.
Frequently Asked Questions
Why does DiskPart say access is denied even though I’m an admin?
Being an administrator in Windows doesn’t automatically give you full control over all disk operations. UAC (User Account Control) still requires you to explicitly run the command prompt as administrator. Additionally, the disk may have hardware or software write protection that even an admin can’t override without clearing the read-only attribute.
Can I fix the access denied error without losing data?
Yes, in most cases. Simply running DiskPart as administrator or clearing the read-only attribute does not delete data. However, if you need to run clean to fix a corrupted disk, that will erase everything. Always back up important files before using DiskPart.
What does the 'clean' command do in DiskPart?
The clean command removes all partition or volume formatting from the selected disk. It effectively makes the disk unallocated, as if it were brand new. It does not securely erase data—it only removes the partition table, so data recovery tools might still recover files.
Does the access denied error occur on external USB drives too?
Yes, it can. External drives often have a physical write-protect switch. If that switch is on, DiskPart will return an access denied error. Also, some USB drives have a software read-only attribute that you can clear with attributes disk clear readonly.
Is there a way to bypass the read-only attribute if the disk is corrupted?
If the disk is corrupted, the read-only attribute might be set to protect the drive from further damage. In that case, you can try using diskpart’s clean command after clearing the attribute, but this will erase all data. If the disk is physically failing, no software command will fix it.