🟣 C# / .NET 6+

Disable Autoplay for All Drives (C#)

Disables Autoplay prompts for every drive type, including USB. Applies the tweak via Microsoft.Win32.Registry.

By WindowsScripting.com · 549 B
SetDisableAutoplayAllDrives.cs
// SetDisableAutoplayAllDrives.cs
//
// Disable Autoplay for All Drives.
// Disables Autoplay prompts for every drive type, including USB.
//
// Usage: dotnet new console -o SetDisableAutoplayAllDrives, replace Program.cs with this
// file, then dotnet run.

using System;
using Microsoft.Win32;

using RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
key.SetValue("NoDriveTypeAutoRun", 255, RegistryValueKind.DWord);

Console.WriteLine("Disable Autoplay for All Drives applied.");