Tuesday, April 19, 2011

Disabling Autorun via C# in Windows

Using C# Autorun can be enabled or disabled for all Removable media types, such as USB, Floppy, etc. 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.

Use the following code:

RegistryKey key;
 
key =  Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\
CurrentVersion\\Policies\\Explorer", true);
 
Rkey.SetValue("NoDriveTypeAutoRun", 255);
//disable for all media types, recommended 
//Rkey.SetValue("NoDriveTypeAutoRun", 95); //disable
//Rkey.SetValue("NoDriveTypeAutoRun", 145); //enable

Manually, you can achieve 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’ and set the desired ‘Decimal' value.

No comments:

Post a Comment