Programatically Disable Autoplay Window in WinForms / C#

I have a program developed in WinForms/C# that watches for SD cards to be inserted into the computer and then does things with them.  I want to disable the autoplay window when my program is running.  Right now the window loads and covers over my own dialog boxes, thus confusing users when things disappear.  How can I disable autoplay programatically in C#?  The solution needs to work with Windows XP, Vista, and 7.

Who is Participating?
Russell_VenableConnect With a Mentor Commented:
Here is the example you are looking for.
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:

Would you please attach a snapshot of the problem you are reporting. Actually I am not getting it correctly.

aj2010Author Commented:
Pop an SD card (or USB flash drive) into your machine and you'll get an AutoPlay box that Windows pops up like attached.  I want to disable this.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Disable it in the register key set the autorun key to 0


or run this file

aj2010Author Commented:
Doesn't work.  Note there is a difference between AutoPlay and Autorun.  Also wouldn't this require a reboot?  I need to disable autoplay temporarily just while my app is running.
aj2010Author Commented:
Doesn't work.  Perhaps this is only good for older versions of windows?  I'm developing on Windows 7.  I also saw the mention about this only working for the foremost window...  took that into account and this doesn't seem to do anything.
hello aj
try this - works for me

//RegisterWindowMessage is a Win32 API call. So you will need to use PInvoke to make it work..
using System.Runtime.InteropServices; 
class Win32Call 
   public static extern int RegisterWindowMessage(String strMessage); 
// In your application you will call 

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.