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:

  1. Intercepting the QueryCancelAutoPlay message
  2. Using the Registry
  3. 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

1. QueryCancelAutoPlay

Note: If your application is using a dialog box you need to call SetWindowLong (signature) instead of just returning false. See here for more details)

2. Registry

Using the registry you can disables AutoRun for specified drive letters (NoDriveAutoRun) or for a class of drives (NoDriveTypeAutoRun)

3. IQueryCancelAutoPlay

Some other links:

Answered By – isamux

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More