Tuesday, April 10, 2018

windows - How to write protect your USB drive using MS DOS ATTRIB?



I'm trying to write protect my USB drive with a batch file. I've learnt that it is possible to do so with ATTRIB +R. The drive switches it's drive letter since it's used on multiple computers. I've tried to use %CD%, but that didn't work. I'm trying to make sure it can't be formatted when protected. Does anyone know how to use the command to write protect an USB drive?


Answer



There is no flag, option, or attribute that would prevent generic USB drives from being erased or formatted.




(That said, you might find various vendor-specific "factory configuration" tools, depending on the actual flash chip that's inside the drive – e.g. UT165 MPTool works with many Kingston drives and offers many features, including read-only mode, custom partitions, and so on. But others only have basic "format" options.)






The +R "read-only" attribute does not write-protect a drive. It protects only individual files, and it is trivial to unset the same way.



Also, the attribute is persistent – once set on a given file, it remains set, no matter where you connect that drive, and no matter what drive letter it has. You don't need a batch file



If you do need a batch file for some task, %0 has the full path of the batch file itself, and it can be modified to %~d0 for the drive letter, %~dp0 for drive+directory, and so on.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...