Forum Discussion
Ottiaia
Aug 13, 2025Iron Contributor
Batch file needed for USB write and read only
I have a requirement for a office purpose. I want to give a usb pendrive write protected and read only permission, for any system I connect, the data shoudnt get deleted anytime in the pendrive. So I know through dispart from cmd we can do this but can anyone help me to create a batch file so the user (non IT) can do it from their own pc without any fuss just by clicking the batch file shortcut rather than typing the commands from command prompy dispart. So pls help me.
1 Reply
- PhysicatitudeCopper Contributor
Run as administrator:
Echo off reg add HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies /v WriteProtect /t REG_DWORD /d 1 /f # Read-only reg add HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies/v WriteProtect /t REG_DWORD /d 0 /f # WritableThe above code can be used to create a batch file to toggle USB write protection.