Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:38+00:00 2026-06-10T08:51:38+00:00

when inserting an USB-Flash drive, Windows normally opens the Autoplay dialog that offers to

  • 0

when inserting an USB-Flash drive, Windows normally opens the Autoplay dialog that offers to browse the drive or if there are multimedia files it offers to choose an app to open them.

We developed a media player that is connected to the USB-Drive and registers itself as Mass Storage Device.

What I need is, that when inserting the Player that this Dialog is not shown, but instead my own application is launched.

Ideally the application would be on the Flash Drive itself, but as I understood is that Autorun is disabled for USB-Drives.

It would be enough if a preinstalled application is launched. I already tried to catch the WM_DRIVE_CHANGE message, but this only works if my application is the top most window, otherwise the Autoplay Dialog is displayed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:51:40+00:00Added an answer on June 10, 2026 at 8:51 am

    after a long research on Google I found this forum post:

    http://social.msdn.microsoft.com/Forums/uk-UA/windowssdk/thread/aef929cb-62ac-4371-b7de-2c07adf3c6a7

    I followed this and here is the working code:

    [Flags()]
    public enum AutorunContent : int
    {
        AutorunInf = 2,
        AudioCD = 4,
        DVDMovie = 8,
        BlankCD = 16,
        BlankDVD = 32,
        UnknownContent = 64,
        AutoPlayPictures = 128,
        AutoPlayMusics = 256,
        AutoPlayMovies = 512
    }
    
    
    [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("DDEFE873-6997-4e68-BE26-39B633ADBE12")]
    public interface IQueryCancelAutoPlay
    {
        [PreserveSig]
        int AllowAutoPlay(
          [MarshalAs(UnmanagedType.LPWStr)] string pszPath,
          [MarshalAs(UnmanagedType.U4)] AutorunContent dwContentType,
          [MarshalAs(UnmanagedType.LPWStr)] string pszLabel,
          [MarshalAs(UnmanagedType.U4)] int dwSerialNumber);
    }
    
    
    public class RunningObjectTableEntry : IDisposable
    {
        private int cookie;
        private IRunningObjectTable rot = null;
        private IMoniker monkey = null;
    
        private RunningObjectTableEntry() { }
    
        /// <summary>
        /// Creates a new entry for the given object
        /// </summary>
        /// <param name="obj">Object to make an entry for. Only one object per class should ever be registered.</param>
        public RunningObjectTableEntry(object obj)
        {
            int hr = GetRunningObjectTable(0, out rot);
            if (hr != 0)
            {
                throw new COMException("Could not retreive running object table!", hr);
            }
    
            Guid clsid = obj.GetType().GUID;
            hr = CreateClassMoniker(ref clsid, out monkey);
            if (hr != 0)
            {
                Marshal.ReleaseComObject(rot);
                throw new COMException("Could not create moniker for CLSID/IID \"" + clsid + "\"!", hr);
            }
    
            cookie = rot.Register(0x01, obj, monkey);   //weak reference, but allow any user
        }
    
        [DllImport("ole32.dll", ExactSpelling = true)]
        private static extern int GetRunningObjectTable([MarshalAs(UnmanagedType.U4)] int reserved, out IRunningObjectTable pprot);
    
        [DllImport("ole32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        private static extern int CreateClassMoniker([In] ref Guid g, [Out] out IMoniker ppmk);
    
        #region IDisposable Members
    
        /// <summary>
        /// De-registers the object and class from the Running Object Table
        /// </summary>
        public void Dispose()
        {
            Marshal.ReleaseComObject(monkey);
            rot.Revoke(cookie);
            Marshal.ReleaseComObject(rot);
        }
    
        #endregion
    }
    
    
    
    [ComVisible(true)]
    [Guid("331F1768-05A9-4ddd-B86E-DAE34DDC998A")]
    [ClassInterface(ClassInterfaceType.None)]
    public class Autoplay : IQueryCancelAutoPlay, IDisposable
    {
        private RunningObjectTableEntry rotEntry;
    
        public Autoplay()
        {
            rotEntry = new RunningObjectTableEntry(this);
        }
    
        #region IQueryCancelAutoPlay Members
    
        public int AllowAutoPlay(string pszPath, AutorunContent dwContentType, string pszLabel, int dwSerialNumber)
        {
            if (pszLabel == "FUNKEYPLAY")  //This is the name of my volume that should not call autoplay
            {
    
    
                return 1;
            }
            else
            {
                return 0;
            }
            //Console.WriteLine("QueryCancelAutoPlay:");
            //Console.WriteLine("   " + pszPath);
            //Console.WriteLine("   " + dwContentType.ToString("x"));
            //Console.WriteLine("   " + pszLabel);
            //Console.WriteLine("   " + dwSerialNumber.ToString());
        }
    
        #endregion
    
        #region IDisposable Members
    
        public void Dispose()
        {
            rotEntry.Dispose();
        }
    
        #endregion
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a menu that will show all files in USB. The
On Windows, is there any way to programatically approve a USB device after insertion,
inserting a .swf or flash files in visual basic asp.net give me coding sample
While inserting rows into SQL Server CE in WP7 I'm getting a SQLCeException that
Looking into possibility of making an USB distributed application that will autostart on insertion
Inserting multilingual data into a SQL 2008 database (nvarchar field) I notice that it
When inserting an object into a database with SQLAlchemy, all it's properties that correspond
I am having trouble inserting values into my Account table that's in a SQL
It's inserting <%= %> into my HTML, but what is that for?
After deleting the partitions from a USB stick and then re-inserting the disk I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.