This post originated from an RSS feed registered with .NET Buzz
by Duncan Mackenzie.
Original Post: Enabling/Disabling AutoRun from your .NET application...
Feed Title: Code/Tea/Etc...
Feed URL: /msdnerror.htm?aspxerrorpath=/duncanma/rss.aspx
Feed Description: Duncan is the Visual Basic Content Strategist at MSDN, the editor of the Visual Basic Developer Center (http://msdn.microsoft.com/vbasic), and the author of the "Coding 4 Fun" column on MSDN (http://msdn.microsoft.com/vbasic/using/columns/code4fun/default.aspx). While typically Visual Basic focused, his blogs sometimes wanders off of the technical path and into various musing of his troubled mind.
I answer quite a few questions on the forums on GotDotNet, and sometimes those answers are interesting enough (in my opinion) to be exposed to a larger audience.... Coding this particular one caused Brian Johnson to say... "cool", so it seems worth posting about here :)
The question was (paraphrased) "How do I stop AutoRun from happening while my app is running and the user puts in a CD?", and the answer is that if your app is the active application, then you can listen for and respond to a certain Windows Message (QueryCancelAutoPlay) and choose to cancel the AutoRun/AutoPlay action for that particular moment (the next CD inserted will result in the message being sent again, and your code gets to choose once again whether or not to cancel the event). Only one Win32 API call is required, RegisterWindowMessage, and overall it is pretty simple code. More details on the underlying functionality is available on MSDN.
Not complicated, but neat enough.... and definitely something I'm going to add to my musicxp system.