⚡ PowerShell 5.1+
Disable Autoplay for All Drives
Disables Autoplay prompts for every drive type, including USB.
Set-DisableAutoplayAllDrives.ps1
<#
.SYNOPSIS
Disable Autoplay for All Drives.
.DESCRIPTION
Disables Autoplay prompts for every drive type, including USB.
Sets HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer \ NoDriveTypeAutoRun to 255.
.EXAMPLE
.\Set-DisableAutoplayAllDrives.ps1
#>
[CmdletBinding()]
param()
$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer'
if (-not (Test-Path $regPath)) {
New-Item -Path $regPath -Force | Out-Null
}
New-ItemProperty -Path $regPath -Name 'NoDriveTypeAutoRun' -Value 255 -PropertyType DWord -Force | Out-Null
Write-Host "Disable Autoplay for All Drives applied. Sign out and back in (or restart explorer.exe) for it to fully take effect." -ForegroundColor Green