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
Besides, this error message will occur when you use the command above on SD card, HDD, SSD, SanDisk drive and more.
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.
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.
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.
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.
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
Step 4. Exit this window and check if it works.
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)
Step 3. Exit this window and then see if you can access your device and data.
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
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.
Step 4. Try the clean command again and see if this error occurs again.
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: Qiling Disk Master 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.
Step 1. Download the write-protected removal tool – free Qiling Disk Master and run it. Right-click the write-protected media in the main page, and then select Format Partition.
Step 2. Select NTFS or FAT32 file system from the drop-down menu.
Step 3. Click Proceed to start the pending operation.
Besides above operation, Qiling Disk Master 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.
Qiling Disk Master, 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 toQiling Disk Master Professional or Qiling Disk Master 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.
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 Qiling Disk Master. 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.