**Disclosure: This post contains affiliate links. If you make a purchase through these links, we may earn a small commission at no extra cost to you.
Many people use USB flash drives to do things such as backup data, transfer files from one computer to another and install operating systems such as Windows and Linux on their PC.
You may come across a situation where you have some important files on your flash drive and need to let someone else use this drive to transfer the files to their computer. You might find yourself worried that they will either erase some of these important files or format your flash drive altogether. As you probably know, to format a flash drive, all you need to do is right click on it and choose the Format option, click on Start and everything will be wiped from the drive, leaving it blank.
The process we will be using to prevent a USB flash drive from being formatted will be done via the command line using the Diskpart tool that comes built into Windows. The Diskpart tool is a command-line utility in Windows designed for managing disks, partitions, and volumes. It allows users to perform various tasks such as creating, deleting, formatting, and resizing partitions, as well as assigning drive letters and cleaning disks.
To begin, open an administrative command prompt by typing cmd in the Windows taskbar search box.
You will then need to type in the following commands and press enter after each one.
Diskpart (used to access the diskpart prompt)
List disk (used to list the drives in your computer)
Select disk X (used to select the disk you want to work with. Change X to the number that corresponds to your flash drive)
Attributes disk set readonly (this will make your flash drive read only)
After the USB flash drive has been made only, you can try to format it and it will look like it is going to work.
But after you click the OK button, you will get a message saying the disk is write protected.
If you want to reverse the process so you can add and remove files from it as well as format it, you can reverse the process.
To do so go through the same process as above using diskpart but this time use the following command at the end.
Attributes disk clear readonly (removes the read only attribute from the disk)
Now you will be able to format your USB flash drive just like you could before.
For additional training resources, check out our online IT training courses.