How to disable Autorun C#
Autorun can be enabled or disabled for all Removable media types, such as USB, Floppy, etc. using C#.
AutoRun, introduced in Windows, enables media and devices to launch programs by use of commands listed in a file called
autorun.inf, stored in the root directory of the medium. But this feature is also used in program like viruses to harm your computer, it is little bit safe if you disable autorun of your computer so that a virus would not attack as you insert a Pendrive or CDs. Avoid double clicking to open
DiscDrive/Pendrives.
Use the following code:
RegistryKey Rkey;
Rkey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
Rkey.SetValue("NoDriveTypeAutoRun", 255);
Manually, you can find this as follows:
Go to Run, type ‘regedit’ press Enter.
Explore as follows:
HKEY_CURRENT_USER -> Software -> Microsoft -> Windows -> CurrentVersion -> Policies -> Explorer.
Double click ‘NoDriveTypeAutoRun’ set value for ‘Decimal'.