AutoPlay
Encyclopedia
AutoPlay, a feature introduced in Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

, examines newly discovered removable media
Electronic media
Electronic media are media that use electronics or electromechanical energy for the end-user to access the content. This is in contrast to static media , which today are most often created electronically, but don't require electronics to be accessed by the end-user in the printed form...

 and devices and, based on content such as pictures, music or video files, launches an appropriate application to play or display the content. It is closely related to the AutoRun
Autorun
AutoRun and the companion feature AutoPlay are components of the Microsoft Windows operating system that dictate what actions the system takes when a drive is mounted....

 operating system feature. AutoPlay was created in order to simplify the use of peripheral
Peripheral
A peripheral is a device attached to a host computer, but not part of it, and is more or less dependent on the host. It expands the host's capabilities, but does not form part of the core computer architecture....

 devices – MP3 players, memory card
Memory card
A memory card or flash card is an electronic flash memory data storage device used for storing digital information. They are commonly used in many electronic devices, including digital cameras, mobile phones, laptop computers, MP3 players, and video game consoles...

s, USB storage devices and others – by automatically starting the software needed to access and view the content on these devices. AutoPlay can be enhanced by AutoPlay-compatible software and hardware. It can be configured by the user to associate favourite applications with AutoPlay events and actions.

Overview

When a user inserts a CD-ROM into a drive or attaches a USB camera, Windows detects the arrival and starts a process of examining the device or searching the medium. It is looking for properties of the device or content on the medium so that AutoPlay can present a set of meaningful options to the user. When the user makes a particular choice, they also have the option to make that selection automatic the next time Windows sees that content or device.

The dialog shows the result of a user placing a DVD into a DVD reader, in this case the D: drive. AutoPlay has determined that content is most likely a DVD movie and presents a set of actions to the user based on that decision. These actions are called Handlers and there are sets of Handlers associated with various types of content. The user can now make their decision and click OK to proceed. However, if they also tick the "Always do the selected action" tick box at this point, they will not be prompted the next time that particular content type is seen on that particular drive; the selected application will automatically start.

AutoPlay properties

If a user regrets that decision or wishes to make automatic AutoPlay selections for any particular content type, the AutoPlay properties for any drive are accessible through the My Computer desktop icon. Selecting a drive and then "File/Properties" from the Windows Explorer
Windows Explorer
This article is about the Windows file system browser. For the similarly named web browser, see Internet ExplorerWindows Explorer is a file manager application that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface...

 menu, followed by the selecting the AutoPlay tab, gives a dialog similar to that shown. The content types can be selected with the drop down box. Here the dialog shows the Handlers available if AutoPlay ever determines the content type on drive D: to be "Pictures". Selecting an action to perform makes that action automatic for that user. Selecting "Prompt me each time to choose an action" deletes any association; AutoPlay will prompt the next time.

The content types available vary with the type of drive selected. Pictures, Music files and Video files are available with any drive. DVD and CD drives can also have "Music CD" or "DVD movie" and Windows Vista adds others like "Video CD movie" to the list.

Mixed content

"Mixed content" is the result of file content types falling into more than one of the Pictures, Music files or Video files content types. Note that a CD containing audio tracks is always considered to be a "Music CD" by Windows, regardless of the presence of data tracks. Therefore a CD with Picture files, Video files and audio tracks is a "Music CD"; it is not "Mixed content".

If this is the result of the AutoPlay decision, the user is always presented with the AutoPlay dialog. This will contain a selection of applications deemed appropriate for the content found. Thus if Music files and Video files are both discovered on a flash drive, the user will get to choose from the Handlers for "Music files" along with the Handlers for "Video files". In this case, the user cannot make their selection the default one.

However, the AutoPlay properties dialog for any drive usually gives "Mixed content" as a content type option. The options available here are limited to actions that can handle any type of files, usually "Open folder to view files" is the only Handler listed here. This enables the user to make that action the default for Mixed content.

Devices that are not drives

Certain types of devices do not appear as drive letters in "My Computer". These are called non-volume devices and AutoPlay handles them somewhat differently from volume
Volume (computing)
In the context of computer operating systems, volume is the term used to describe a single accessible storage area with a single file system, typically resident on a single partition of a hard disk. Similarly, it refers to the logical interface used by an operating system to access data stored on...

 devices like CDs and DVDs. Many digital cameras and video devices fall into this category.

As Windows cannot examine the files on the device to determine content type, it is left to the manufacturer to decide how to proceed. A manufacturer can register Handlers against their particular device, can add their device to a group of devices (e.g.: ZipDrives) or allow a device class (e.g.: all devices which are Video Cameras) to handle their device for them. This determines which Handlers will be listed in the AutoPlay dialog when their device is discovered.

As these type of devices do not have a drive letter, AutoPlay properties cannot be accessed and changed through "My Computer". However, when a device is attached, the discovery causes Windows to place an icon in the taskbar notification area (commonly referred to as the tray). AutoPlay preferences for this device can now be changed by clicking this icon. The image to the left shows the icon that appeared when a video camera was attached.

Default settings

On a new installation of Windows, a default set of handler applications are registered with the AutoPlay system. The following are the defaults with Windows XP SP2. The Action and Provider are simply strings stored within the Handler, they can vary to give the user a better idea of what will happen if they choose that action. They can also change to suit a user's preferred language. Many Handlers use the same Windows application; for example, Windows Media Player is used to play Music files as well as DVD movies. The word "using" is added by AutoPlay to join the two strings neatly.
Content Action Provider
Music files Play Windows Media Player
Open folder to view files Windows Explorer
Pictures Copy pictures to a folder on my computer Microsoft Scanner and Camera Wizard
View a slideshow of the images Windows Picture and Fax Viewer
Print the pictures Photo Printing Wizard
Open folder to view files Windows Explorer
Video files Play Windows Media Player
Open folder to view files Windows Explorer
Mixed content Open folder to view files Windows Explorer
Music CD Rip music from CD Windows Media Player
Play audio CD Windows Media Player
Open folder to view files Windows Explorer
DVD movie Play DVD movie Windows Media Player
Open folder to view files Windows Explorer

Windows 95 and Windows 98

Windows 95 and Windows 98 do have a primitive version of AutoPlay. Its sole job is to deal with Audio CDs and Movie DVDs and start an application to deal with them. If the new arrival does not fall into one of these categories Windows proceeds with the usual AutoRun process.

The action taken with Audio CDs and Movie DVDs essentially considers both types of media as if they were files; Explorer then simply performs the default action associated with that file type. File types and the actions associated with them can be viewed and changed from within any Explorer folder from the "File Types" tab of the "Tools/Folder Options" menu. They are stored in the Registry
Windows registry
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user...

 under HKEY_CLASSES_ROOT.

If the CD is a Red Book
Red Book (audio CD standard)
Red Book is the standard for audio CDs . It is named after one of the Rainbow Books, a series of books that contain the technical specifications for all CD and CD-ROM formats.The first edition of the Red Book was released in 1980 by Philips and Sony; it was adopted by the Digital Audio Disc...

 standard format Audio CD, then Explorer calls the default action registered for the AudioCD file type. This is normally set to "Play" and commonly calls cdplayer.exe.

If the DVD is a Movie DVD then Explorer calls the default action registered for the DVD file type. Movie DVDs are recognised by the existence of the file \video_ts\video_ts.ifo. The action for DVD is also normally set to "Play" and commonly calls dvdplay.exe.

The fact that the check for Audio CDs and Movie DVDs is done before AutoRun has implications for disabling the automatic playing of these types of media. Disabling AutoRun via the Registry or Group Policy or looking for QueryCancelAutoPlay messages within an application does not prevent these media types from automatically playing on insertion.

However one can disable Audio CDs by editing the file type for AudioCD and clicking "Set default". This will remove the Play action as the default for that file type. Alternatively, changing the (Default) entry under the HKEY_CLASSES_ROOT\AudioCD\Shell key to "" (a blank string) will accomplish the same thing. The disabling action for Movie DVDs is the same, with "DVD" used in place of "AudioCD".

The pertinent Registry settings are shown below along with their defaults in Windows 98SE:


HKEY_CLASSES_ROOT\AudioCD\shell
(Default) "Play"

HKEY_CLASSES_ROOT\AudioCD\shell\play
(Default) "&Play"

HKEY_CLASSES_ROOT\AudioCD\shell\play\command
(Default) "%SystemRoot%\cdplayer.exe /play %1"

HKEY_CLASSES_ROOT\DVD\shell
(Default) "Play"

HKEY_CLASSES_ROOT\DVD\shell\play
(Default) "&Play"

HKEY_CLASSES_ROOT\DVD\shell\play\command
(Default) "%SystemRoot%\system32\dvdplay.exe /play %1"

From detection to application

The illustration shows how AutoPlay proceeds to the execution of an application in response to the detection of hardware or media by the Shell Hardware Detection service.


Image:AutoPlay_flow.png|AutoPlay process flow. This image has an associated image map.|460px|none|thumb

rect 92 90 248 118 #Volumes
rect 92 146 248 174 #AutoRun
rect 92 202 248 230 #Content sniffing
rect 271 230 399 258 #PerceivedType
rect 92 258 248 286 #Content types
rect 92 314 248 342 #EventHandler (volume)
rect 92 370 248 426 #Handler table lookup
rect 92 454 248 482 #Dialogs and decisions
rect 101 483 239 594 HKLM\...\AutoPlayHandlers\Handlers\handler

rect 271 426 429 454 HKLM\...\AutoPlayHandlers\EventHandlers\ShowPicturesOnArrival

rect 524 90 680 118 #Non-volumes
rect 524 146 680 174 #Device characteristics
rect 524 202 680 230 #Device Handler
rect 524 258 680 286 #Events and Handlers
rect 524 314 680 342 #EventHandler (non-volume)
rect 524 370 680 426 #Handler table lookup
rect 524 454 680 482 #Dialogs and decisions
rect 533 483 671 510 HKLM\...\AutoPlayHandlers\Handlers\handler

rect 703 174 859 202 HKLM\...\AutoPlayHandlers\DeviceClasses\{CC7BFB41-F175-11D1-A392-00E0291F3959}
rect 703 342 861 370 HKLM\...\AutoPlayHandlers\DeviceHandlers\VideoCameraDeviceHandler\EventHandlers\DeviceArrival
rect 703 426 861 454 HKLM\...\AutoPlayHandlers\EventHandlers\VideoCameraArrival

desc bottom-left


The process flow is examined by initially dividing it into two groups by device type. The division lasts until the "Handler Table(s) Lookup" stage, when the AutoPlay process becomes much the same for both types of devices. Each part of the process, along with any relevant Registry entries, is described in subsequent sections.

The AutoPlayHandlers key

AutoPlay relies on the Windows Registry to store all its settings. All machine-wide AutoPlay settings are rooted on the following key:

HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoPlayHandlers

As this is a rather unwieldy key to refer to, this article will use an abbreviated version:

HKLM\...\AutoPlayHandlers

Device types

There are two basic categories of devices as viewed by Windows and by AutoPlay. The volume based devices are those for which the GetDriveType Windows API call returns one of:
Type name Description
DRIVE_REMOVABLE The drive is removable (floppy drive, USB and FireWire drives)
DRIVE_FIXED The disk cannot be removed from the drive (hard disk)
DRIVE_REMOTE The drive is a remote (network) drive
DRIVE_CDROM The drive is a CD-ROM or DVD-ROM drive
DRIVE_RAMDISK The drive is a RAM disk


All volume based devices show up under My Computer
Windows Explorer
This article is about the Windows file system browser. For the similarly named web browser, see Internet ExplorerWindows Explorer is a file manager application that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface...

 with a drive letter. They present Windows with a file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

 which is accessible using Explorer and which AutoPlay can examine (or sniff) to see what types of files they contain. Many volume based devices need a medium (a CD, disk or card) inserted and mounted
Mount (computing)
Mounting takes place before a computer can use any kind of storage device . The user or their operating system must make it accessible through the computer's file system. A user can access only files on mounted media.- Mount point :A mount point is a physical location in the partition used as a...

 to show as an accessible volume in My Computer. For AutoPlay to function, the device must have AutoRun-compatible drivers
Device driver
In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....

 which will notify the system that a disk has been inserted. Some devices, like floppy
Floppy disk
A floppy disk is a disk storage medium composed of a disk of thin and flexible magnetic storage medium, sealed in a rectangular plastic carrier lined with fabric that removes dust particles...

 drives cannot notify the system when a disk is inserted and will not produce an AutoPlay dialog.

The non-volume based devices are those which are not volumes, i.e. everything else. Digital cameras, video cameras, certain portable music players and anything which does not show up under My Computer is a non-volume device. However, the more modern the camera or music player is, the more likely it is to present Windows with a viewable file system. These types of cameras and players would thus be considered volume devices.

Events and Handlers

The discovery of a new medium or device by the Shell Hardware Detection service is termed an Event. There are four different types of Events: the Arrival and Removal of "Devices" and the Arrival and Removal of "Media". These Event types are labelled appropriately: DeviceArrival, DeviceRemoval, MediaArrival and MediaRemoval.

Although it would seem appropriate that the arrival of a volume would be a MediaArrival and the arrival of a non-volume a DeviceArrival, none of these Event types are used for volumes at all (See EventHander (volume)).

Handlers, as discussed previously, are the actions presented to the user when AutoPlay is invoked. A Handler is a grouping of the information describing how an application is to be called along with textual information, normally localised
Internationalization and localization
In computing, internationalization and localization are means of adapting computer software to different languages, regional differences and technical requirements of a target market...

 to the user's preferred language, which is used to represent the action in the AutoPlay dialog. Multiple Handlers can use a single application, calling it in different ways or with different options. The information stored in a Handler is described in more detail in the Handlers section.

AutoRun

If a file called autorun.inf
Autorun.inf
An autorun.inf file is a text file that can be used by the AutoRun and AutoPlay components of Microsoft Windows Operating systems. For the file to be discovered and used by these components, it must be located in the root directory of a volume...

 exists in the root directory
Root directory
In computer file systems, the root directory is the first or top-most directory in a hierarchy. It can be likened to the root of a tree — the starting point where all branches originate.-Metaphor:...

 of the file system, settings in that file can add to the options presented to the user or affect the view AutoPlay has of the content. Under Windows XP, the existence of this file may affect the process flow – AutoRun can proceed to executing an application directly without user intervention. Under Windows Vista, AutoRun cannot bypass AutoPlay in this way; it can only add to the options presented to the user. The Inf handling section of the AutoRun article details when and whether AutoPlay is invoked.

The AutoRun layer initially consults Windows Registry values to decides whether to initiate actions for any particular drive or drive type. If AutoRun has been disabled for the newly discovered volume, then the process halts at that point, effectively disabling AutoPlay for that volume.

Content sniffing

After AutoRun completes, AutoPlay initiates by doing an examination of the volume for content. This is called content sniffing. AutoPlay decides whether the volume is an Audio CD, movie DVD, a blank recordable medium (a CD-R, CD-RW, DVD+R etc.) or a generic volume which contains files.

In the case of a generic volume, AutoPlay starts with the root directory and searches the file system to a depth of four directory levels below the root directory to find file types that fall into certain categories or "content types".

If this search takes more than a second or so, a progress dialog shows the scanning process taking place. This dialog can easily be confused with an Explorer copy operation; however, no files are being copied or moved.

Content types

As far as AutoPlay sniffing is concerned, files fall into three main categories or "content types". Files outside these categories are not of interest:
Pictures   .jpg .gif .bmp .png ...
Music   .mp3 .wav .wma ...
Video   .avi .mpg ...


Content is considered to be "Mixed content" if files fall into more than one of the three categories.

Content is considered to be Unknown if the content sniffing process finds no categorisable content. This does not mean that there are no files present, just no files falling into one or more of the above three content types. In this case AutoPlay opens an Explorer window on the root directory of the medium and the process flow finishes here.

PerceivedType

In order to class files into the three content types, the PerceivedType value associated with various file extensions is used to make the category determination. PerceivedType can be set to "image", "audio" or "video" to class files into Pictures, Music or Video content types respectively. There are other PerceivedTypes known to Windows (text, compressed, system and application) but these are not relevant to AutoPlay.

All file type information is stored in the Registry under HKEY_CLASSES_ROOT. The following is the PerceivedType Registry information for .avi Video files and .mp3 Music files:


HKEY_CLASSES_ROOT\.avi
(Default) "avifile"
PerceivedType "video"

HKEY_CLASSES_ROOT\.mp3
(Default) "mp3file"
PerceivedType "audio"

EventHandler (volume)

The EventHandler is the title of a table that makes an association between various Handlers and the triggering Event. In the case of volume-based events, the EventHandlers are generated completely internally to AutoPlay with no reference to the Registry.

Note that examination of the AutoPlayHandlers section of the Windows Registry reveals the ContentTypeSniffers and ContentTypeHandlers keys. Off these keys, various subkeys and values would appear to relate to and even control volume-based AutoPlay. However, as of Windows XP SP2, these keys are defined solely for future use and are not accessed by AutoPlay.

One of the following predefined EventHandlers are chosen based solely on the decision AutoPlay makes internally after volume examination and content sniffing:
Media or content type EventHandler
Pictures ShowPicturesOnArrival
Music files PlayMusicFilesOnArrival
Video files PlayVideoFilesOnArrival
Mixed content MixedContentOnArrival
Blank CD-R/CD-RW HandleCDBurningOnArrival
Music CD PlayCDAudioOnArrival
DVD movie PlayDVDMovieOnArrival
Added in Windows Vista
Super VideoCD movies PlaySuperVideoCDMovieOnArrival
VideoCD movies PlayVideoCDMovieOnArrival
An autorun.inf specifies an executable AutorunINFLegacyArrival

Device characteristics

As Windows cannot perform content sniffing on non-volume devices, AutoPlay analyses these devices by their characteristics rather than by their content. Every newly discovered device has identification information, normally stored within the device itself. This information is gather by enumerators and is used to build identification strings which Windows refers to when accessing and referring to the device. An identification string for a particular device is called a Device ID.

In order to uniquely identify each instance of each device that is installed, Windows assigns an Instance ID to each device. This ID contains location information, or a serial number if supported.

Combining the Device ID with the Instance ID gives a string which uniquely identifies an individual device in a system. This is the Device Instance ID. An example of a string from a PCI device is:
PCI\VEN_1274&DEV_1371&SUBSYS_8030107B&REV_04\0&0E


When Windows discovers a new device, it stores the Device Instances in the Registry from:
HKLM\SYSTEM\CurrentControlSet\Enum


The Windows Device Manager (Located under the System icon in the Control Panel) will reveal the Device Instance ID for any particular device. Getting the Properties of any device, selecting the Details tab of the Properties dialog and selecting "Device Instance ID" from the drop down box will retrieve the information.

Another characteristic of every device is the Device Interface Class. This defines an interface contract, where a device agrees to support a basic set of Input/Output Control
Ioctl
In computing, ioctl, short for input/output control, is a system call for device-specific operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; the effect of a call depends completely on the request code. Request codes are...

 calls pertaining to that Device Interface Class. For example, a device agreeing to support the keyboard interface contract must support the IOCTL_KEYBOARD_QUERY_ATTRIBUTES IOCTL call, amongst others. Each class is represented as a large universally unique number called a GUID
Globally Unique Identifier
A globally unique identifier is a unique reference number used as an identifier in computer software. The term GUID also is used for Microsoft's implementation of the Universally unique identifier standard....

.

A device can register many Device Interface Class GUIDs for itself, contracting to support various appropriate interface calls. The most common Interface Class GUID relating to storage devices is the Volume Device Interface Class GUID, {53F5630D-B6BF-11D0-94F2-00A0C91EFB8B}.

Device Interface Class GUIDs can be found in the Registry under:
HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses.

Device Handler

When a non-volume device is being analysed, AutoPlay looks in several places in the Registry for a DeviceHandlers entry. This is simply a string which, when combined with other information, selects an EventHandler (which tables the Handlers). The DeviceHandlers entries are commonly placed into the Registry by the manufacturer of the device. There are also broader categories of devices which have preassigned DeviceHandlers, Video Camera devices for example.

The first place AutoPlay looks is under the Device Parameters key of the device instance. For example:
USB\Vid_059b&Pid_0031&REV_0100


is the USB device identification string for an Iomega USB ZIP drive. Combined with a USB serial number, say 059B003112010E93, this forms the Device Instance ID for the device. Thus the Device Parameters key is found at:


HKLM\...\Enum\USB\Vid_059b&Pid_0031\059B003112010E93\Device Parameters
Icons ""
NoMediaIcons ""
Label ""
DeviceHandlers "ZipDeviceHandler"


The DeviceHandlers value in this case is "ZipDeviceHandler". Other device parameters may also be present here: Icons may specify an icon to represent the device along with NoMediaIcons to represent the device when it has no media present. Label specifies a friendly name for the device.

If no DeviceHandlers entry is found under the device instance, AutoPlay checks for the existence of a DeviceGroup entry, again under the device instance. This allows a whole set of devices to share device parameters.


HKLM\...\Enum\USB\Vid_059b&Pid_0031\059B003112010E93\Device Parameters
DeviceGroup "ZipDrive100"


The parameters for this device group are stored in:
HKLM\...\AutoPlayHandlers\DeviceGroups\devicegroup


So for the ZipDrive100 group example:


HKLM\...\AutoPlayHandlers\DeviceGroups\ZipDrive100
Icons "%SystemRoot%\system32\shell32.dll,-230\0\0"
Label "Zip Drive 100"
DeviceHandlers "ZipDeviceHandler"


Lastly, AutoPlay searches the relevant Device Interface Class GUIDs. The parameters for device classes are stored in:
HKLM\...\AutoPlayHandlers\DeviceClasses\{classguid}


Here is the entry that the Microsoft application Movie Maker registers for any and all Video Camera devices:


HKLM\...\AutoPlayHandlers\DeviceClasses\{CC7BFB41-F175-11D1-A392-00E0291F3959}
DeviceHandlers "VideoCameraDeviceHandler"
Label "@C:\Program Files\Movie Maker\wmm2res.dll,-63094"
Icons "C:\WINDOWS\system32\shell32.dll,-317\0\0"

EventHandler (non-volume)

Once a Device Handler is selected, it is combined with the triggering Event to produce a Registry key relative to the AutoPlayHandlers key:

HKLM\...\AutoPlayHandlers\DeviceHandlers\devicehandler\EventHandlers\event

For example, on the arrival of a Video Camera, the Device Handler is "VideoCameraDeviceHandler" and the event is "DeviceArrival". The key looked up is:


HKLM\...\AutoPlayHandlers\DeviceHandlers\VideoCameraDeviceHandler\EventHandlers\DeviceArrival
VideoCameraArrival ""


The result is the EventHandler name which in this case is "VideoCameraArrival". The entry data is empty.

Handler table lookup

Once an EventHandler name is chosen, the corresponding table is used to build a list of Handlers. Each table is stored at
HKLM\...\AutoPlayHandlers\EventHandlers\eventhandler


and consists of a list of entries. The entry name is the name of the Handler and the entry data is blank.

For example, if the result of the AutoPlay volume analysis is the ShowPicturesOnArrival EventHandler, the corresponding table could look like this:


HKLM\...\AutoPlayHandlers\EventHandlers\ShowPicturesOnArrival
MSWiaEventHandler
MSShowPicturesOnArrival
MSPrintPicturesOnArrival
MSOpenFolder


This would result in four Handlers being chosen to represent the Event in the AutoPlay dialog. In the above example, the Handler names listed do correspond to the choices given for the "Pictures" section shown in the table of default settings.

Handlers

The information for each Handler is stored at:
HKLM\...\AutoPlayHandlers\Handlers\handler


and consists of a set of entries which determine the application to be called and the descriptions of the action in the AutoPlay dialog. The Handler information differs depending on whether or not the system can read the device contents directly. By including the appropriate information, a single Handler can support both volume and non-volume events. MSWiaEventHandler (The Camera and Scanner Wizard) is an example of this type of Handler.

Given the volume Handler MSShowPicturesOnArrival, the information entries could look something like:


HKLM\...\AutoPlayHandlers\Handlers\MSShowPicturesOnArrival
DefaultIcon "%SystemRoot%\system32\SHELL32.dll,-249"
Action "@%SystemRoot%\system32\SHELL32.dll,-17156"
Provider "@%SystemRoot%\system32\SHELL32.dll,-17157"
InvokeProgID "Shell.AutoplayForSlideShow.1"
InvokeVerb "open"


The DefaultIcon, Action and Provider entries are used in the AutoPlay dialog as follows:



The Action and Provider values can be literal strings or references to resource
Resource (Windows)
In Microsoft Windows, resources are read-only data embedded in EXE, DLL, CPL or MUI files.The Windows API provides for easy access to all applications' resources.-Types:...

 strings. Resource strings have the distinct advantage of having a language associated with them. In an English locale, the Action resource reference in the example above might equate to "View a slideshow of the images", but in another locale the string could automatically display in the appropriate language.

The DefaultIcon value can either be the name of a .ico file or an icon resource. Icon resources are referenced in a similar manner to string resources except that @ symbol is not used. Icons can be stored in a binary file in two ways: If the number after the file name is less than zero then the number is the resource ID; otherwise the number is the index of the icon. It is recommended to use the negative numbered resource IDs.

The InvokeProgID and InvokeVerb values are used to start the application via the ShellExecuteEx API call. This is the same method used to, say, start Notepad when a user double-clicks on a .txt file; the application is not started directly. The values are Registry keys under HKEY_CLASSES_ROOT. In the example above, the relevant key would be:
HKEY_CLASSES_ROOT\Shell. AutoplayForSlideShow.1


Non-volume Handlers are stored alongside the volume Handlers but they look slightly different. Given that the data on the device is only accessible through an interface and not directly readable using a file system, the Handler information entries deal primarily with starting the application (if not already running) via the Windows Component Object Model
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

 (COM) infrastructure. AutoPlay then uses the COM links thus established to feed information about the event that occurred and the device that caused it.

Here is the Registry information for the non-volume Handler, MSVideoCameraArrival:


HKLM\...\AutoPlayHandlers\Handlers\MSVideoCameraArrival
DefaultIcon "C:\Program Files\Movie Maker\moviemk.exe,0"
Action "@C:\Program Files\Movie Maker\wmm2res.dll,-63095"
Provider "@C:\Program Files\Movie Maker\wmm2res.dll,-100"
InitCmdLine ""C:\Program Files\Movie Maker\moviemk.exe" /RECORD"
ProgID "Shell.HWEventHandlerShellExecute"
CLSIDForCancel "{AB007EC8-E2D4-4664-ACD9-1D059681F3DE}"


The DefaultIcon, Action and Provider entries are the same as before, however InitCmdLine and ProgID are used instead of InvokeProgID and InvokeVerb. The CLSIDForCancel entry shown above is for information purposes only. A CLSID entry can be used instead of ProgID, the latter being preferred. ProgID refers to the HKEY_CLASSES_ROOT entry where the appropriate COM CLSID can be found.

The ProgID value points to a COM component implementing the IHWEventHandler interface and the InitCmdLine value is used with the IHWEventHandler::Initialize method. Technical details are available from the articles referred to in the External Links section below.

Available Handlers

On a default installation of Windows, there are a pre-existing set of Handlers available. This is a list of the default Handlers present on an installation of Windows XP SP2. Handlers may change name over time or be merged – MSPlayMusicFilesOnArrival and MSPlayVideoFilesOnArrival were merged into MSPlayMediaOnArrival when Windows Media Player took over the handling of music and video file content types.
Volume (files) Non-volume (interface)

MSOpenFolder



MSCDBurningOnArrival

MSWMPBurnCDOnArrival



MSPlayMediaOnArrival

MSShowPicturesOnArrival

MSPrintPicturesOnArrival



MSPlayCDAudioOnArrival

MSRipCDAudioOnArrival

MSPlayDVDMovieOnArrival



MSPlayVideoCDMovieOnArrival

MSPlaySuperVideoCDMovieOnArrival



MSWiaEventHandler

MSTakeNoAction

MSPromptEachTime

MSPromptEachTimeNoContent



MSVideoCameraArrival

MSSHAudioDevHandler



MSWMDMHandler

MSWPDShellNamespaceHandler



MSWiaEventHandler


Note that MSWiaEventHandler (The Camera and Scanner Wizard) can handle both volume and non-volume devices, MSPlayMediaOnArrival handles both music and video and MSWMDMHandler is the "Windows Media Device Manager" which handles certain types of non-volume music players.

Dialogs and decisions

Once the list of Handlers is chosen the DefaultIcon, Action and Provider entries from each Handler are used to build the icons and strings that display the choices in the AutoPlay dialog. A particular item in the dialog may be selected as the default (highlighted) choice. This default can be modified using Registry settings. The dialog may not always be shown; a choice may be made automatically depending on user preferences.

User preferences are stored in an AutoPlayHandlers section under HKEY_CURRENT_USER:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoPlayHandlers

Setting a user's default highlighted preferences is achieved by adding entries to:
HKCU\...\AutoPlayHandlers\EventHandlersDefaultSelection


in the form: eventhandler = "handler". For example,
ShowPicturesOnArrival = "MSOpenFolder"


will make that Handler the default for the ShowPicturesOnArrival EventHandler table.

Automatic AutoPlay selections is set through the AutoPlay tabs on the relevant properties dialogs. The settings are stored under HKEY_CURRENT_USER but have changed position in various versions of Windows. The setting is stored as an entry name which is a combination of information from the MountedDevices section of the Registry (HKLM\SYSTEM\MountedDevices) plus the EventHandler name, and entry data which is the Handler name. It is possible to manually trace the strings used by parsing MountedDevices manually or tracing back from the ParentIdPrefix settings under the enumeration tree, however this is undocumented and unlikely to be portable between Windows versions.

However, to illustrate the setting, this is the data that is used when AutoPlay is configured for a flash drive (note that the entry name is wrapped due to length):


HKCU\...\AutoPlayHandlers\UserChosenExecuteHandlers
H:\\?\STORAGE#RemovableMedia#7&34ec5d6b&0&RM#{53f5630d-b6bf-
11d0-94f2-00a0c91efb8b}+PlayMusicFilesOnArrival = "MSPlayMediaOnArrival"

Disabling AutoPlay

Disabling AutoPlay for volume devices can be done by changing AutoRun specific Registry settings (see AutoRun above).

However, prior to Windows 7, disabling AutoPlay for any non-volume device is not possible without an application intervening to cancel the triggering event (see Cancellation below). From Windows 7, there is a "Turn off Autoplay for non-volume devices" Group Policy available.

Cancellation

Volume cancellation can be done through an application by listening to the QueryCancelAutoplay Windows message, or by implementing the IQueryCancelAutoplay COM interface.

Non-volume cancellation is achieved by implementing the IHWEventHandler COM interface.

Further specifics are available from the November 2001 MSDN Magazine article on AutoPlay along with code examples from the AutoPlay Demo CodeProject.com article.

Other settings

From Windows Vista and Windows Server 2008, the "Don't set the always do this checkbox" Group Policy is available. If this policy is Enabled, the "Always do this..." checkbox in the AutoPlay dialog will not be set by default when the dialog is shown.

From Windows Vista, at the Dialogs and decisions point of the AutoPlay execution sequence, there is a check to see if the key is currently being held down. If so, any automatic user preferences are ignored and the AutoPlay dialog is always shown.

See also

  • AutoRun
    Autorun
    AutoRun and the companion feature AutoPlay are components of the Microsoft Windows operating system that dictate what actions the system takes when a drive is mounted....



Software providing similar functionality in other environments
  • gnome-volume-manager in GNOME
    GNOME
    GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. It is composed entirely of free and open source software...

  • Thunar
    Thunar
    Thunar is a file manager for Linux and other Unix-like systems, written using the GTK+ 2 toolkit, and shipped with Xfce version 4.4 RC1 and later. Thunar is developed by Benedikt Meurer, and was originally intended to replace XFFM, Xfce's previous file manager...

     (using the thunar-volman plugin) in Xfce
    Xfce
    Xfce is a free software desktop environment for Unix and other Unix-like platforms, such as Linux, Solaris, and BSD – though recent compatibility issues have arisen with regard to BSD Unix platforms...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK