HOWTO: Disable AutoPlay

ID: Q150449


The information in this article applies to:


SUMMARY

Windows 95 includes the AutoPlay feature that allows for automatic activation of a program when a CD-ROM compact disc is inserted into the CD- ROM drive.

While is is possible to programmatically disable this functionality, Microsoft recommends that developers avoid modifying this behavior. Any such modifications will globally affect the operating system, potentially creating a situation where AutoPlay fails because it is left "turned off." In this event, there is no interface available to the user to restore normal operation.

In rare cases, however, it may be necessary for an application to temporarily disable this feature. An example of such a program would be a program to catalog compact discs that requires the user to insert compact discs to be scanned in rapid succession without running any software from the compact discs.

For cases such as this, there are two registry entries that control this behavior, one for data compact discs and a different one for audio compact discs.

Because there is no API or synchronization object to control access to these registry entries, it is possible that multiple programs or multiple instances of the same program could interfere with each other. It is the responsibility of the programmer to take precautions against this.


MORE INFORMATION

For data compact discs, the registry entry that controls AutoPlay is a bitmask in the following location:


   HKEY_CURRENT_USER\ 
      Software\ 
         Microsoft\ 
            Windows\ 
               CurrentVersion\ 
                  Policies\ 
                     Explorer\ 
                        "NoDriveTypeAutoRun" 
This registry entry is fully described in the following article in the Microsoft Knowledge Base:

Q136214 How to Test Autorun.inf Files

To programmatically toggle the switch for AutoPlay of data compact discs, perform the following steps:
  1. Use RegOpenKeyEx to get a handle to the previously listed key.


  2. Use RegQueryValueEx to get the current value of NoDriveTypeAutoRun.


  3. Use XOR with that value with 0x20 (the bit for the CD-ROM drive type).


  4. Use RegSetValueEx to write the value from step 3 back into the registry, overwriting the original value.


  5. Close the handle to the key.


This change will not affect the behavior when an Audio compact disc is inserted into the drive. The following registry entry defines the default behavior for Audio compact disc insertion:

   HKEY_CLASSES_ROOT\ 
      AudioCD\ 
         Shell\ 
            "" 
By default, this value is set to Play, which will cause Cdplayer.exe to execute upon AudioCD insertion. To toggle this behavior programmatically, perform these steps:
  1. Use RegOpenKeyEx to get a handle to the previously listed key.


  2. Use RegQueryValueEx to get the current value of the default entry ("").


  3. If the value is Play, change it to an empty string (""). If the value is an empty string, change it to Play.


  4. Use RegSetValueEx to write the value from step 3 back into the registry, overwriting the original value.


  5. Close the handle to the key.

    This change will take effect immediately.


Additional query words:


Keywords          : kbRegistry kbWin32s kbWinOS95 kbGrpVCDB 
Version           : winnt:
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: April 13, 1999