|This section can contain one or more of the following values: icon, label, open, ShellExecute, and UseAutoPLAY.
The icon entry value is a text string. It may contain either a path to an icon (.ICO) file or a path to an executable file followed by a comma and the numeric identifier of the icon resource (resource ID) contained in the file (as I've just shown in the code). If the resource ID is positive, it denotes the index of the resource within the file; if negative, it denotes a resource ID number. References using icon index values may be invalidated if icon resources move within the file. Therefore it is recommended that resource IDs be used instead of index values.
The label value is simply a string. This value is new to Windows 2000 and Windows Me and will have no effect on prior releases. These two values, icon and label, are used to represent the associated drive in the Windows shell.
The open value is used to specify the command line that will be executed when some media triggers Autoplay. The value should contain a valid path (relative to the root of the media) to an executable file followed by any required arguments.
The ShellExecute value was introduced in Windows 2000 and Windows Me. It is similar to the open value, but the command line provided is passed to the ShellExecuteEx API instead of the CreateProcess API. Unlike CreateProcess, ShellExecuteEx works with file associations to run the application associated with the specified file. For example, if you specify readme.txt as the command, ShellExecuteEx will likely run Notepad to edit the readme.txt file. If CDs will be used on versions of Windows that do not support the ShellExecute value, the Autorun.INF file should include both the ShellExecute and open commands.
Finally, the UseAutoPlay value should be set to 1 for media that want to use the new Autoplay V2 features on platforms that support it. This value was introduced in Windows XP and will have no effect on prior versions of Windows. When this value is present, it will take precedence over the open and ShellExecute values. As with the ShellExecute value, this value should be used with care. It is intended primarily for use with multimedia content for which Autoplay support was added to Windows XP. If the media might be used on earlier versions of Windows, the Autorun.INF file should also provide a value for open, since UseAutoPlay has no effect on Windows versions prior to Windows XP.
To maintain support for existing media using Autoplay V1 features, Autoplay V2 drops back to V1 behavior in some scenarios. If Autoplay V2 finds an Autorun.INF file without a UseAutoPlay=1 entry, or detects an audio CD or a DVD movie, then Autoplay V2 behaves as Autoplay V1 used to behave.
Since personalization is a key feature of the Windows XP shell, one of the advantages of Autoplay V2 is that the user can associate favorite applications with the various events and actions provided through Autoplay. Furthermore, as the adoption of Windows XP increases over time, the need for media to support the older Autoplay features will diminish.
Autoplay Support for Audio CDs
All CD media containing audio tracks are considered to be audio CDs by Windows XP, regardless of the presence of data tracks. Applications that want to handle audio CD events register under HKEY_CLASSES_ROOT\AudioCD. This registration works on all versions of Windows that support Autoplay.
Windows XP introduces a new registration scheme for audio CDs that allows multiple applications to register for specific Autoplay events and actions. CDs containing music content are a good example. Since music is a popular content type, it is common for multiple music-related applications to be installed on a computer at the same time. Prior to Autoplay V2, the installation of a new application would replace the Autoplay registration of the previously installed application such that only the most recently installed application would respond to Autoplay events, even though both applications were installed on the system.
To remedy this problem, audio CDs can now use the Autoplay V2 registration. This new registration scheme allows for more than one application to be registered for the same content type and provides ways for the user to pick the preferred application and to change it at will. Coexistence of these applications is now possible.
Information on how to register for Autoplay V2 is presented later in this article. The Autoplay V1 registration mechanism is still supported for backward compatibility. If an application registers for Autoplay using both the V1 and V2 mechanisms, Windows XP will ignore the V1 registration and use only the V2 registration.
Autoplay Support for DVD Movies
Autoplay support for DVD movies was added to Windows 98. Autoplay handles audio CDs and DVD movies in similar ways. The primary difference in the handling of CDs and DVD movies is the way Autoplay identifies the media type. Autoplay checks for the presence of the video_ts.ifo file inside the video_ts folder located in the media's root folder. On all versions of Windows that support DVD Autoplay, applications can register under the HKEY_CLASSES_ROOT\DVD key in a process similar to audio CD registration. Also, as described earlier for audio CDs, Autoplay V2 introduces a new registration mechanism for DVD movie handlers.
Automatically Opening Folders
On Windows Me and Windows 2000, Autoplay V1 opens a folder to display the contents of a newly mounted hard disk drive or to display the contents of network drives mapped through the Map Network Drive menu option in Windows. Likewise, if there is an Autorun.INF file on a CD media and the open or ShellExecute command is not specified, Windows will open a folder on the root of the drive. Starting with Windows XP, Autoplay V2 opens a folder following the insertion of media in a CD drive or removable disk drive if it can't find an Autorun.INF file and the Autoplay V2 content sniffing does not find any known content. Content sniffing is new to Autoplay V2 and is explained later in this article. This behavior also applies to removable hard disks, like USB and 1394 hard disks.
Event Categories in Autoplay V2
Like its predecessor, Autoplay V2 provides a software response to hardware actions initiated by the user on the machine. The primary difference between Autoplay V1 and V2 is the dynamic nature of Autoplay V2. When determining what actions to suggest or perform in response to an event, Autoplay V2 considers the event in conjunction with the various programs registered on the computer. In contrast, Autoplay V1 would always statically run the same application pointed to in the Autorun.INF file, or play an Audio CD or DVD movie using the respective default application. Two categories of events are handled by Autoplay V2: volume-based device events and non-volume-based device events.
Volume-based device events are events that affect devices that appear as volumes in Windows XP—that is, all disk drives accessible via Windows file system APIs. This includes CD drives, removable disk drives, hard disk drives, removable media readers, and mass storage devices. Basically, if it shows up under My Computer with a drive letter, it's a volume-based device.
Non-volume-based devices include, well, everything else. Specific examples of these devices include digital video cameras and portable music players that do not expose their content as a file system supported by Windows XP. This does not mean that all video cameras and portable music players are non-volume devices. For example, newer digital cameras and portable music players that use the USB Mass Storage stack are treated as volume devices since they appear to the system as volumes.
Digital camera devices which are non-volume devices get special treatment from Windows. Even though they are non-volume devices, they are handled by the Windows Image Acquisition (WIA) component for backward compatibility reasons. For more information on WIA, see: Windows Image Acquisition.
Autoplay V2 on Volume-based Devices
Figure 1 describes the various types of volume devices. The classification is based on the return values from the Win32® API function GetDriveType.
Volume devices can also be categorized as removable or not (the device itself, not the media). For example, volume Autoplay considers USB and 1394 hard disks for Autoplay, but does not consider nonremovable hard disks. This mostly eliminates internal disks for which Autoplay would not be appropriate.
Volume Autoplay V2 relies on sniffing the content of volumes as they arrive, whether they're media for removable media drives or removable hard disks. This sniffing consists of scanning the first four levels of folders from the root of the volume and looking for multimedia content types: music, graphics, and video. If an application registers file extensions for files which are graphics, music, or video, then a PerceivedType value should be added under the file extension key and its value should be set to "image", "audio", or "video", respectively. When Autoplay sniffs media for content types, files which have their extension appropriately tagged will be identified as belonging to the proper content type. For some media, more than one of these content types will be found; these will be referred to as mixed content media.
Since Windows can read the content of volume devices, registration of applications is done on a per-content type basis rather than on a per-device basis. When an event occurs, Windows determines which action to perform based on the intersection of the applications registered on a per-content type basis and the content types found on the volume through sniffing.
Figure 2Volume Autoplay Event Prompt
If the user did not yet specify any preferences, Windows prompts the user to choose one of the applications, as illustrated in Figure 2. If the user has previously selected a preferred application for the event, Windows automatically launches the preferred application. Once the user selects a default application, this preference can be changed through the AutoPlay tab in the volume's properties in My Computer (see Figure 3).
Figure 3Volume Autoplay Property Sheet
Let's consider an example to clarify this behavior. When the user inserts a compact flash card containing Windows Media Audio (WMA) files (compressed music files), Windows sniffs the media and finds the music content. The first time the user inserts such content in the compact flash reader, Windows prompts the user to choose an appropriate handler from a list of all applications registered for this content type. Out of the box, Windows XP provides three options when prompting the user: Play using Windows Media™ Player, Open folder to view files, and Take no action. Other applications can register to be included in this list; more on this later.
The prompt also has an "Always do the selected action" checkbox which, when checked, enables the user to set the selection as the default action to perform for the current content type. Once a preference has been established, the original behavior can be restored by checking the "Prompt me each time to choose an action" checkbox in the device's Autoplay properties (see Figure 3).
When a volume contains mixed content, the prompt does not offer the "Always perform the selected action" option. In this situation, the dialog contains a list of all applications registered for the type of content found. The "Always perform the selected action" option is not always provided because there are numerous combinations of content which will cause the mixed content prompt to appear. If the content combination is different the next time around, rendering any fixed preference would be inappropriate. For example, assume a user inserts mixed content media containing digital images and video. The prompt presented is the mixed content prompt. If the "Always perform the selected action" option was available and the user indicated they always want to use Windows Slide Show as the viewing application for this content type, then later when the user inserts other mixed content media containing digital video and music. The original preference of using Windows Slide Show is most likely inappropriate for digital video and music. Because of this, users are always prompted to choose an application when mixed content media is inserted into the drive.
Autoplay V2 on Non-volume-based Devices
The non-volume-based events are events generated by all other non-volume devices. Windows cannot read the content of such devices. It is also possible that such a device does not support the concept of content. Because of these factors, registration of apps for non-volume Autoplay devices is done on a per-device basis rather than a content-type basis.
When one of these devices is connected to the machine, Windows checks to see if an application has been registered for the device. If the user has not yet specified a preference, he is prompted to choose one of the registered Autoplay handlers (see Figure 4). If the user has already picked a preferred application for the event, that application is automatically launched by Windows.
Figure 4Non-volume Autoplay Event Prompt
Once a default application has been selected, that preference can be changed by clicking a small icon that appears in the taskbar notification area when the device is connected (see Figure 5). This approach is different from the way preferences are changed for volume-based devices. The difference is necessary as many non-volume-based devices do not appear in the My Computer folder. Thus, there is no place to host the Autoplay property page.
Autoplay V2 Registration Mechanism
Both volume and non-volume Autoplay now support a new registration mechanism for applications interested in responding to media Autoplay events. With this new mechanism, multiple applications may be registered concurrently for events related to the same content type. This concurrent registration provides a more event-related experience for the user. Autoplay settings are stored in the registry. All settings are rooted on the following key: