Some users reported getting an error message saying “Diskpart has encountered an error, The media is write protected” after using the clean or clean all commands in DiskPart. Additionally, this problem may also appear when mounting SD cards, HDDs, SSDs, SanDisk drives, among others. In case you’re dealing with the same issue on your computer, this post might help you fix it.
What causes Diskpart to encounter a Media write protection error?
There are a few mass storage devices that provide file and folder protection through write protection. Unfortunately, sometimes the files and folders cannot be accessed. Furthermore, some drives lack a write-protection switch but can still be set to read-only. Below are some possible reasons for this.
- You might have bad sectors on your drive.
- Malware or viruses have infected your storage media.
- Disks are set to read-only in the Registry or in Property.
- The media can no longer be writeable if the read-only mode is accidentally activated.
- The read-only mode is accidentally activated and the media becomes un-writable.
Diskpart has encountered an error, The media is write protected
It is recommended that you first backup your files and then try the suggestions below to fix this error effectively.
1] Modify the Registry Editor
Try changing the WriteProtect key’s value in the Registry to see if that solves the issue. You can do this using the below steps:
- The first step is to open the Registry Editor. In order to do this, press the Windows key + R to open Run. Type regedit into the textbox, then click OK. When UAC appears on the screen, click on the Yes button.
- Once you are in the Registry Editor, go to the following location:
Note: Alternatively, you can just copy and paste the below path line in the address bar of the Registry Editor and press Enter. Your computer will automatically take you there.
- If you do not see the StorageDevicePolicies key in the following location, you need to create it.
- To do so, right-click on Control and then select New > Key.
- Then name it StorageDevicePolicies.
- You now need to create a new 32-bit DWORD value named WriteProtect.
- For this, right-click on StorageDevicePolicies, choose New > DWORD (32-bit) Value, and then name it WriteProtect.
- Click twice on the newly created WriteProtect key, and then when the popup menu appears, change the Value data to 0.
- Lastly, click OK to save the changes.
Now close the Registry Editor window and check if you are able to access the storage device and data.
2] Remove Read Only Attribute
If the Diskpart clean command fails to run correctly due to the media being write-protected on USB, SD Cards, HDDs, or SSDs, clear the read-only attributes and see if it helps. Here is how to do this:
- Run Command Prompt as an Administrator. To do so, open the Run window. Once it opens, type cmd in the search bar and press the key combination Ctrl+Shift+Enter.
- In the Command Prompt window, type diskpart and press Enter.
- Then, run the commands in the order listed below:
list disk select disk n attributes disk clear readonly clean
Note: In the above command, n represents the number of devices to be cleaned
- After you perform the above steps, now close the window, and check if it works.
3] Repair the corrupted system file
A corrupted file system can also result in this issue. If you encounter such a problem, you can use Diskpart to remove all write-protection files and reformat the disk.
- Open Command Prompt as an administrator.
- On the next page, type diskpart and press Enter.
- Now run the commands below one after another:
list disk select disk m attributes disk clear readonly clean create partition primary format fs=fat32
Note: In the above command line, m refers to the drive containing the corrupted file system
When you have completed the above steps, close this window and check if your device and data are accessible.
How can I clean Diskpart?
Using the clean command in Diskpart will erase the entire disk and its partitions. When you have cleaned your entire disk, you can use the Diskpart utility to create new partitions. In this article, we discussed the whole process.