⚡ 100% FREE Single Standalone Executables under 100 KB •No Install•No Telemetry•No Ads
🔒 Step-by-Step Windows Troubleshooting & 1-Click Portable Utilities

How to Disable USB AutoPlay & Write-Protect Flash Drives in Windows 11

Learn why infected USB thumb drives automatically run malware scripts in Windows, how to lock down AutoPlay via the Registry, and how to toggle USB port Write-Protection against data theft.

⚡ Quick Answer: How to Stop USB AutoPlay & Write-Protect in Windows 11

To permanently disable USB AutoPlay, run Command Prompt as Admin and execute:
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun /t REG_DWORD /d 255 /f
To make USB drives Read-Only (Write-Protected), set:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" /v WriteProtect /t REG_DWORD /d 1 /f
Or use Pexoris USBShield to apply both settings and immunize your flash drives in 1-click.

Why USB Flash Drives are Still the #1 Physical Attack Vector

Despite cloud storage, millions of USB flash drives are plugged into school computers, photo print kiosks, library workstations, and office PCs every single day. A single infected computer can silently copy a malicious .vbs or .exe file disguised as a folder onto your thumb drive.

By default, Windows AutoPlay attempts to scan the drive and read the autorun.inf file the instant it is inserted. If the user clicks anywhere on the AutoPlay prompt or double-clicks a fake folder shortcut, the malware executes with the full security token of the logged-in user.

Method 1: Disable AutoPlay Completely via Windows Registry (CMD)

The most reliable method to eliminate USB execution risks is modifying the Windows Shell Explorer policies. This applies to both local computer accounts and newly created profiles:

  1. Press Win + X and select Terminal (Admin) or Command Prompt (Admin).
  2. Execute the following commands to disable drive autorun on all removable devices:
Command Prompt (Admin)
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun /t REG_DWORD /d 255 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoAutorun /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" /v DisableAutoplay /t REG_DWORD /d 1 /f

255 (or 0xFF in hex) instructs Windows to disable AutoPlay on all device types, including removable disks, fixed drives, CD-ROMs, and network shares.

Method 2: Kernel-Level Autorun.inf Parser Redirection

A lesser-known defense mechanism utilized by enterprise sysadmins is redirecting the Windows INI file mapping table for autorun.inf. This ensures that even if an infected drive contains an autorun file, the Windows kernel refuses to parse its contents:

Command Prompt (Admin)
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf" /ve /t REG_SZ /d "@SYS:DoesNotExist" /f

Method 3: How to Lock USB Ports in Read-Only Mode (Write-Protection)

When inserting a critical backup drive into an untrusted computer, or when managing computers in an office where employees should not be allowed to copy confidential documents out to thumb drives, you can enable hardware write-protection:

Enable USB Write-Protection (CMD)
reg add "HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" /v WriteProtect /t REG_DWORD /d 1 /f

To restore full Read and Write permissions later:

Disable USB Write-Protection (CMD)
reg add "HKLM\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" /v WriteProtect /t REG_DWORD /d 0 /f
Prefer an Instant 1-Click Solution?

Download Pexoris USBShield — a 59 KB standalone portable utility. Toggle AutoPlay blocking, enable Read-Only mode, and immunize USB drives without typing registry commands.

Download Pexoris USBShield →

How Flash Drive Vaccine Immunization Works

Older Windows systems or computers where registry access is locked can be protected using an Autorun Vaccine. Pexoris USBShield creates an un-deletable folder named autorun.inf on the root of your drive.

In Windows, a folder and a file cannot share the exact same name in the same directory. Because a directory named autorun.inf with reserved subfolders and System/Hidden attributes already exists, any virus trying to create a malicious autorun.inf file will fail with an access denied error.