Can I disable window autoplay function programatically with C#/.NET?
Does anybody know a way to deactivate the autoplay function of windows using c#/.NET?
A little summary, for all the others looking for a good way to disable/supress autoplay.
So far I’ve found 3 methods to disable autoplay programatically:
- Intercepting the QueryCancelAutoPlay message
- Using the Registry
- Implementing the COM Interface IQueryCancelAutoPlay
In the end I chose the 3rd method and used the IQueryCancelAutoPlay interface because the others had some signifcant disadvantages:
- The first method
(QueryCancelAutoPlay) was only able
to suppress autoplay if the
application window was in the foreground, cause only the foreground window receives the message
- Configuring autoplay in the registry worked even if the application window was in the background. The downside: It required a restart of the currently running explorer.exe to take effect…so this was no solution to temporarily disable autoplay.
Examples for the implementation
- Suppressing AutoRun Programmatically (MSDN article)
- CodeProject: Preventing a CD from Auto-Playing
- Canceling AutoPlay from C#
Using the registry you can disables AutoRun for specified drive letters (NoDriveAutoRun) or for a class of drives (NoDriveTypeAutoRun)
- Using the Registry to Disable AutoRun (MSDN article)
- How to Enable / Disable Autorun for a Drive (using Registry)
- Windows 7 AutoPlay Enable | Disable
- Reference for the IQueryCancelAutoPlay interface on MSDN
- IQueryCancelAutoPlay only called once? (Example implementatio, also read comments)
- AutoPlayController (another implementation, not tested)
Some other links:
- Enabling and Disabling AutoRun (MSDN article)
- Autoplay in Windows XP: Automatically Detect and React to New Devices on a System (an old but extensive article on Autoplay)
Answered By – isamux