Click here to Skip to main content
13,144,928 members (50,389 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 1 Apr 2011

How to disable Autorun C#

, 8 Apr 2011
Rate this:
Please Sign up or sign in to vote.
How to disable Autorun C#
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); //disable for all media types, recommended 
//Rkey.SetValue("NoDriveTypeAutoRun", 95); //disable
//Rkey.SetValue("NoDriveTypeAutoRun", 145); //enable

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'.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Gun Gun Febrianza26-May-13 9:37
member Gun Gun Febrianza26-May-13 9:37 
GeneralRe: Thanks for the info. Much appreciated. Pin
Keith.Badeau9-May-11 6:16
memberKeith.Badeau9-May-11 6:16 
GeneralAre there values for disabling individual types? For instanc... Pin
Keith.Badeau8-May-11 3:19
memberKeith.Badeau8-May-11 3:19 
GeneralRe: Yes, Code would be same but value is different. Like 20 is t... Pin
Brijesh Kr8-May-11 17:47
groupBrijesh Kr8-May-11 17:47 
GeneralAlternate Pin
Steve Wellens2-Apr-11 11:22
memberSteve Wellens2-Apr-11 11:22 
GeneralRe: Alternate Pin
Brijesh Kr4-Apr-11 23:12
groupBrijesh Kr4-Apr-11 23:12 
GeneralRe: Alternate Pin
Steve Wellens5-Apr-11 2:22
memberSteve Wellens5-Apr-11 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 8 Apr 2011
Article Copyright 2011 by Brijesh Kr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid