[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2083
  • Last Modified:

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.

Thanks.
0
aj2010
Asked:
aj2010
1 Solution
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hi,

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

Regards,
VSS
0
 
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.
AutoPlay.png
0
 
IngCharlieCommented:
Disable it in the register key set the autorun key to 0

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CDRom]
"Autorun"="0"

or run this file

disable-autorun.reg
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.
0
 
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.
0
 
r3nderCommented:
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 
{ 
[DllImport("user32.dll")] 
   public static extern int RegisterWindowMessage(String strMessage); 
} 
 
// In your application you will call 
 
Win32Call.RegisterWindowMessage("QueryCancelAutoPlay"); 

Open in new window

0
 
Russell_VenableCommented:
Here is the example you are looking for.
 http://www.pinvoke.net/default.aspx/user32.registerwindowmessage
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now