Diskpart Has Encountered an Error: The Media Is Write Protected

When you meet the Diskpart clean error: Diskpart has encountered an error the media is write protected during cleaning your disk using Diskpart, here you can find the reason and the corresponding solution.

Emily

By Emily / Updated on May 12, 2023

Share this: instagram reddit

About this error

When you use Diskpart clean or clean all command on USB drive, you may receive the following error message.

Diskpart has encountered an error the media is write protected

See the system event log for more information

Disk is Write Protected

Besides, this error message will occur when you use the command above on SD card, HDD, SSD, SanDisk drive and more.

Causes of  “DiskPart has encountered an error the media is write protected”

On the market, there is some mass storage device providing a write-protection function to protect files and folders. However, sometimes, you still cannot access files and folders. Besides, some drive does not have a write-protection switch and still can be set to read-only mode. In the following, I’ll list some possible causes.

▶Your storage media is damaged by virus or malware.

▶You accidentally set the read-only switch to ON side and the media becomes un-writable.

▶You set the disk is to read-only in Property or Registry.

▶Your drive has physical damages, such as bad sectors.

Solutions to “Diskpart has encountered an error the media is write protected"

To fix this error and ensure the security of your data, you’d better to backup files first and then try the following solutions one by one. Some of the following operations will lead to data loss.

1. Change the value of Write-protect key in Registry

Step 1. Type regedit in the Run window.

Step 2. Navigate to the following sub-key and find the WriteProtect key on the right panel.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies

Step 3. If there is no StorageDevicePolicies key, you need to create one. Right-click on Control, select New andKey option in order and then name it as StorageDevicePolicies.

Create New Key

 

Step 4. Right-clickStorageDevicePolicies, select New andDWORD (32-bit) Value and then name it as WriteProtect.

Step 5. Right-click the newly created WriteProtect key and change the Value to 0. And then click OKto exit this window.

Step 6. Check if you can access your storage device and data.

2. Type attributes disk clear readonly command first

When you use Diskpart clean command but receive Diskpart has encountered an error the media is write protected on USB/SD card/HDD/SSD, you can type attributes disk clear readonly command prior to typing clean or clean all command.

Step 1. Type cmd in the search box, right-click it and select Run as administrator.

Step 2. Type diskpart in the pop-up window and press Enter.

Step 3. Type the commands below in order and hit Enter to run it.

▶list disk

▶select disk n (n refers to the number of device you want to clean)

▶attributes disk clear readonly

▶clean

Clear Read Only

Step 4. Exit this window and check if it works.

3. Repair the corrupted file system

If your drive has corrupted file system, you can use Diskpart to clear all write-protection file attributions from the disk and reformat it again.

Step 1.Open cmd and type diskpart in the window.

Step 2. Type the commands below and press Enter.

▶list disk

▶select disk m (m refers to the drive containing corrupted file system)

▶attributes disk clear readonly

▶clean

▶create partition primary

▶format fs=fat32 (or format fs=ntfs)

Repair FIle System

Step 3. Exit this window and then see if you can access your device and data.

4. Change Read-only mode

If the device is in read-only mode, you need to check it first, and then change the Current Read-only State from Yes to No.

Step 1. Open cmd window and type diskpart in the command prompt.

Step 2. Type the following commands and hit Enter.

▶list disk

▶select disk r ( r refers to the disk you want to clean)

▶attribute disk

Attribute Disk

 

This command tells you if your device is in read-only mode. If yes, see Step 3. If not, try to format the media for reuse.

Step 3. Type attributes disk clear readonly command in the command prompt and hit Enter.

Notes:✎...
1. If your disk is locked by an active process, you still need to reboot the computer.
2. If your device is USB drive, you still need to check the write-protect switch.

Step 4. Try the clean command again and see if this error occurs again.

5. Format the write protected media for reuse

Formatting partition is the last resort to write-protected issues. It will lead to data loss if you do not have a file backup. To fix the Diskpart clean error: Diskpart has encountered an error the media is write-protected, you can use the free partition manager: AOMEI Partition Assistant Standard. It can format USB drive/SD card/ HDD/SSD, which is write-protected due to corrupted file system. And all the steps are very easy to learn, even for a beginner. You just need to follow the steps below and move your finger.

Download Freeware Win 11/10/8.1/8/7/XP
Secure Download

Step 1. Download the write-protected removal tool – free AOMEI Partition Assistant and run it. Right-click the write-protected media in the main page, and then select Format Partition.

Format Partition

Step 2. Select NTFS or FAT32 file system from the drop-down menu and click OK to exit.

Partition Label

Step 3. Click Apply and then Proceed to start the pending operation.

Apply

Besides above operation, AOMEI Partition Assistant can help you do more things and fix some problems. You can use it to move partition to end of the disk, clone Windows to USB drive, etc. Also, you can use it to fix virtual disk service error the volume size is too big, extend volume greyed out, Diskpart has encountered an error access is denied, etc.

AOMEI Partition Assistant, the free version of partition manager, can satisfy all your basic needs. But if you want to fix the problem free version cannot or just get more features, you can upgrade toAOMEI Partition Assistant Professional or AOMEI Partition Assistant Server according. The advanced versions allows you to convert MBR to GPT without deleting partitions, allocate free space, convert dynamic disk to basic one without losing data, and more.

Wrapping things up

To fix Diskpart has encountered an error the media is write-protected, you can try to change the value of the Writeprotect key in Registry, type attributes disk clear readonly first and then clean, repair corrupted file system of the media, change the read-only mode from Yes to No.

If none of the above methods works for you, you can try the last one – formatting partition with AOMEI Partition Assistant. With it, all things become easy. You do not need to learn the complicated commands, which will lead to data loss if one of the processes goes wrong. In this software, all steps are fixed and there is little risk to make a mistake.

Emily
Emily · Staff Editor
Emily is an English editor of AOMEI Technology; she has a great passion for providing easy solutions for people to tackle with all disk or partition management problems. In addition to writing articles about disk/partition management, she also edits great tutorials on how to back up and restore disk for data security. In her spare time, she loves to learn computer skill to improve herself or stay with her family to enjoy a good day.