Introduction
USB storage devices such as pen drives, USB flash drives, and external hard drives are commonly used to transfer data between computers. However, in corporate offices, educational institutions, organizations, and business environments, unrestricted USB storage access can create serious security risks.
Unauthorized USB devices can be used to:
Copy confidential company data.
Transfer sensitive information outside the organization.
Introduce malware or viruses into computers.
Connect unauthorized external storage devices.
Create data leakage and security compliance issues.
One effective way to control these risks is to restrict USB storage devices using Windows Registry policies through a Batch (.bat) file.
In this guide, we will learn how to enable and disable USB storage restrictions in Windows 10, Windows 11, and above using simple batch files.
The best part: This method targets USB removable disk storage devices only. It does not intentionally disable USB keyboards, USB mice, or other USB input devices.
1. How Does This Method Work?
Windows provides built-in Removable Storage Access policies that allow administrators to control access to removable storage devices.
We will use the following registry location:
reg
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
This GUID identifies the Removable Disks device class.
We will configure three registry values:
Registry Value | Function |
|---|---|
Deny_Execute | Blocks execution access |
Deny_Read | Blocks reading data |
Deny_Write | Blocks writing data |
By enabling all three policies, users are prevented from reading, writing, or executing files on supported removable disk devices.
Important: These policies target removable disk storage, not all USB devices. USB keyboards and mice use different device classes, so they are not intentionally blocked by this configuration.
2. Enable USB Storage Restriction Using Batch File
First, create a new text file and rename it:
ENABLE_USB_RESTRICTION.bat
Copy and paste the following code into the file.
Enable USB Restriction Batch Code
batch
@echo off
title Enable USB Removable Disk Restrictions
color 0A
:: Check Administrator privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo.
echo ==========================================
echo ENABLE USB REMOVABLE DISK RESTRICTIONS
echo ==========================================
echo.
:: Registry path for Removable Disks
set "KEY=HKLM\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"
:: Backup existing policy settings
reg export "HKLM\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices" "%~dp0USB_POLICY_BACKUP.reg" /y >nul 2>&1
:: Enable Deny Execute Access
reg add "%KEY%" /v Deny_Execute /t REG_DWORD /d 1 /f
if errorlevel 1 goto FAILED
:: Enable Deny Read Access
reg add "%KEY%" /v Deny_Read /t REG_DWORD /d 1 /f
if errorlevel 1 goto FAILED
:: Enable Deny Write Access
reg add "%KEY%" /v Deny_Write /t REG_DWORD /d 1 /f
if errorlevel 1 goto FAILED
echo.
echo ==========================================
echo SUCCESS: ALL THREE POLICIES ENABLED
echo ==========================================
echo.
echo Execute Access : DENIED
echo Read Access : DENIED
echo Write Access : DENIED
echo.
echo Updating Group Policy...
gpupdate /target:computer /force
echo.
echo Operation completed.
echo Backup: USB_POLICY_BACKUP.reg
echo.
pause
exit /b 0
:FAILED
echo.
echo ERROR: Failed to configure one or more policies.
echo Check Administrator privileges and Windows edition.
echo.
pause
exit /b 1
How to Run the Enable Batch File
Save the file as ENABLE_USB_RESTRICTION.bat.
Right-click the batch file.
Select Run as administrator.
Click Yes when the User Account Control prompt appears.
Wait until the registry policies are configured.
The script will update computer Group Policy.
Expected result USB removable disk read, write, and execute access will be denied when the policies are applied.
3. Disable USB Storage Restriction Using Batch File
Whenever you want to restore USB storage access, you can use a second batch file.
Create a new text file and rename it:
DISABLE_USB_RESTRICTION.bat
Copy and paste the following code.
Disable USB Restriction Batch Code
batch
@echo off
title Set USB Removable Disk Restrictions - Not Configured
color 0E
:: Check Administrator privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo.
echo ==========================================
echo USB REMOVABLE DISK - NOT CONFIGURED
echo ==========================================
echo.
:: Registry path for Removable Disks
set "KEY=HKLM\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"
:: Backup current settings before modification
reg export "HKLM\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices" "%~dp0USB_POLICY_BEFORE_NOT_CONFIGURED.reg" /y >nul 2>&1
:: Remove Deny Execute Access
reg delete "%KEY%" /v Deny_Execute /f >nul 2>&1
:: Remove Deny Read Access
reg delete "%KEY%" /v Deny_Read /f >nul 2>&1
:: Remove Deny Write Access
reg delete "%KEY%" /v Deny_Write /f >nul 2>&1
echo.
echo ==========================================
echo SUCCESS: ALL THREE POLICIES REMOVED
echo ==========================================
echo.
echo Execute Access : NOT CONFIGURED
echo Read Access : NOT CONFIGURED
echo Write Access : NOT CONFIGURED
echo.
echo Updating Group Policy...
gpupdate /target:computer /force
echo.
echo ==========================================
echo OPERATION COMPLETED
echo ==========================================
echo.
echo Backup: USB_POLICY_BEFORE_NOT_CONFIGURED.reg
echo.
pause
exit /b 0
How to Run the Disable Batch File
Save the file as DISABLE_USB_RESTRICTION.bat.
Right-click the file.
Select Run as administrator.
Approve the administrator permission prompt.
Wait for the Group Policy update to complete.
After applying the changes, removable disk access should return to the state determined by other applicable Windows policies.
Expected result The three USB removable disk restriction values will be removed from the specified registry key.
4. What Happens to Keyboard and Mouse?
One of the most important advantages of this method is that it targets the Removable Disks device class rather than disabling USB ports or USB controllers.
Device | Expected Behaviour |
|---|---|
USB Pen Drive | Restricted |
External USB Hard Drive | Restricted |
USB Flash Storage | Restricted |
USB Keyboard | Unaffected |
USB Mouse | Unaffected |
USB Printer | Unaffected |
USB Webcam | Unaffected |
Note: Actual behaviour depends on device classification, Windows policy processing, and other installed security policies. Test the configuration with your organization's hardware before deployment.
5. How to Verify USB Storage Restrictions
After running the enable batch file, you can verify the registry configuration.
Follow these steps:
Press Win + R.
Type regedit.
Press Enter.
Navigate to the following registry location:
reg
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
You should find these three DWORD values:
Name | Expected Data |
|---|---|
Deny_Execute | 1 |
Deny_Read | 1 |
Deny_Write | 1 |
When all three values are set to 1, the corresponding access restrictions are configured.
6. Important Points Before Using These Scripts
Before deploying these scripts on office or enterprise computers, consider the following:
Administrator rights: Both scripts require administrator privileges.
Registry backup: The enable script creates a backup of the existing removable storage policy key.
Windows compatibility: These registry policies are supported on applicable Windows 10 and Windows 11 editions.
Existing policies: Domain Group Policy, Microsoft Intune, or other management tools may override local settings.
Policy refresh: Run the scripts and check the output of gpupdate for errors.
Existing USB sessions: Already-open files and existing device sessions may require disconnecting and reconnecting the storage device or restarting Windows.
Backup restoration: Removing the three values does not necessarily restore the exact previous configuration if other policies existed. The backup file should be retained.
Security recommendation: Test the scripts on a non-production computer before applying them to multiple systems.
7. Frequently Asked Questions (FAQs)
Q1. Will this method disable my USB keyboard and mouse?
No. The configuration targets the Removable Disks device class and does not intentionally disable USB keyboards or mice.
Q2. Does this method work on Windows 10?
Yes, on supported Windows 10 editions with the applicable Removable Storage Access policies.
Q3. Does it work on Windows 11?
Yes. The same registry-based policy approach is supported on applicable Windows 11 editions.
Q4. Can users copy files from a USB pen drive after applying this restriction?
No, when the Deny Read policy is successfully applied, reading files from supported removable disks is blocked.
Q5. Can users copy files from the computer to a USB drive?
No, when the Deny Write policy is successfully applied, writing files to supported removable disks is blocked.
Q6. How can I enable USB storage access again?
Run DISABLE_USB_RESTRICTION.bat as administrator. It removes the three configured policy values.
Q7. Will this block USB printers?
The policy targets removable disk storage rather than USB printers. However, individual device classification and other security policies can affect the result.
Conclusion
Restricting USB storage devices is an important security measure for organizations that want to prevent unauthorized data transfers and reduce the risk of malware infections.
Using these two simple batch files, administrators can:
Restrict USB pen drives and external hard drives.
Block USB storage read, write, and execute access.
Keep USB keyboard and mouse functionality unaffected by this policy.
Enable or disable restrictions whenever required.
Create registry backups before making policy changes.
This is a simple and convenient approach for managing USB removable storage access on Windows 10 and Windows 11 computers without disabling USB ports completely.
Recommended for: IT Administrators, System Administrators, Desktop Support Engineers, and Corporate IT Security Teams.