How to disable AutoPlay

This article was previously published under Q150449
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
Windows 95 includes the AutoPlay feature that allows for automaticactivation 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. Anysuch modifications will globally affect the operating system, potentiallycreating a situation where AutoPlay fails because it is left "turned off."In this event, there is no interface available to the user to restorenormal operation.

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

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

Because there is no API or synchronization object to control access tothese registry entries, it is possible that multiple programs or multipleinstances of the same program could interfere with each other. It is theresponsibility of the programmer to take precautions against this.
MORE INFORMATION
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows
For data compact discs, the registry entry that controls AutoPlay is abitmask 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 theMicrosoft Knowledge Base:

136214 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 (clear the bit if set, or set the bit if cleared) with the current value of NoDriveTypeAutoRun 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 isinserted into the drive. The following registry entry defines the defaultbehavior for Audio compact disc insertion:
   HKEY_CLASSES_ROOT\       AudioCD\          Shell\             ""				
By default, this value is set to Play, which will cause Cdplayer.exe toexecute 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.
Properties

Article ID: 150449 - Last Review: 12/04/2015 14:37:18 - Revision: 2.4

Microsoft Win32 Application Programming Interface

  • kbnosurvey kbarchive kbhowto kbregistry KB150449
Feedback