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

0

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?

Jaïr Paalman

Posted 2015-11-18T10:26:59.100

Reputation: 201

Answers

0

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.

user1686

Posted 2015-11-18T10:26:59.100

Reputation: 283 655

Thanks you, but there is a way to write protect a drive in such a way that it can't be formatted without special actions. I've read ways to undo this by using DISKPART and CLEAN. I can't however, find a way to write protect it that way. I'm trying to lock it so that if I lose it, others can't edit or format it. The problem is, that I have to use it on computers that I have no admin rights on, so I can't use programs. – Jaïr Paalman – 2015-11-18T11:39:56.847

@JaïrPaalman - What you read isn't accurate. Everything in this answer is of course correct. Provide us with your source that says otherwise, I guarantee you, there is a logical explanation to the explain the differences in the reality and what you are reading. – Ramhound – 2015-11-18T13:40:46.313

DISKPART doesn't really count as a "special action" anyway. Things like MPTool might, though they work on a much lower level than partitioning. – user1686 – 2015-11-18T16:23:40.677

Though. If you lose the drive, what is the actual problem with someone else editing or formatting it? It's not going to force them to return the drive to you. If anything, they'll just consider it broken and throw it away. – user1686 – 2015-11-18T16:26:26.337

I'm using it for school work. If they can't use it, they'll probably leave it where I can find it back. Also, it's a nice challange. – Jaïr Paalman – 2015-11-19T22:44:26.930