How to get READONLY Status for Current disk drive (usb) - like diskpart/attr disk

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Eureka!
Posts: 137
Joined: 25 Jul 2019 18:25

Re: How to get READONLY Status for Current disk drive (usb) - like diskpart/attr disk

#16 Post by Eureka! » 02 Oct 2021 18:16

Code: Select all

@echo off & setlocal

for %%x in ("%__CD__%") do set "ThisVolume=%%~dx"

(
   echo sel vol %ThisVolume%
   echo attr disk
) | diskpart | ( findstr /i "Read-only  : No" >nul && echo Disk is not protected!)

   

That works because selecting a volume will implicitly select the right disk too.

Post Reply