AutoPlay

  About AutoPlay

  AutoPlay Command Reference


AutoPlay

  About AutoPlay

  Introduction

  How AutoPlay Works

  The Autorun.inf File

  Tips for Writing AutoPlay Applications

  Suppressing AutoPlay

  AutoPlay for MS-DOS–Based Applications

  AutoPlay Command Reference


AutoPlay

  About AutoPlay

  AutoPlay Command Reference

  defaulticon

  icon

  open

  shell

  shell\verb


About AutoPlay

Microsoft® AutoPlay is a feature of the Microsoft Windows® 95 operating system. When a user inserts a CD with AutoPlay into a CD-ROM drive on a Windows 95-based platform, AutoPlay automatically starts an application on the CD that can install, configure, and run the product. AutoPlay automates the procedures for installing and configuring products for Windows 95-based platform that are distributed on CDs.

You can use AutoPlay to install and run CD-ROM applications that run with Windows 95, whether the application is based on the MS-DOS® operating system, Windows 3.0, Windows 3.1, or Windows 95.

For your CD-ROM product to display the Microsoft Windows 95 logo, it must be enabled for AutoPlay.

Note

MS-DOS and previous versions of Windows (versions 3.0 and higher) ignore AutoPlay. Adding AutoPlay to the CD does not hinder or alter user interaction when the CD-ROM is installed on a platform for MS-DOS, Windows 3.0, or Windows 3.1.


How AutoPlay Works

The implementation of AutoPlay relies on three items: CD-ROM device drivers, the autorun.inf file, and an application that installs and runs your product:

•	32-bit CD-ROM device drivers.

CD-ROM device drivers for Windows 95 detect the event when a user inserts a CD into a CD-ROM drive. This feature was not present in device drivers of previous versions of MS-DOS and Windows. When a user inserts a CD into a CD-ROM drive, Windows 95 immediately checks to see if the CD has a personal computer file system. If it does, then Windows 95 looks for a file named autorun.inf.

•	Autorun.inf.

This file resides on the CD and specifies an application that AutoPlay runs. This file can contain other information as well.

•	Startup application.

Although you can run any application on the CD by specifying it in the autorun.inf file, typically the application performs a startup or installation function. By including your own startup application, you can control the process to install, uninstall, and run the program distributed on the CD.


The Autorun.inf File

The autorun.inf file is a text file located in the root directory of a CD. This file specifies the startup application associated with the CD and the icon that is displayed in Windows Explorer and My Computer. You can also specify customized menu items for the CD in autorun.inf. These menu items are added to the shortcut menu that is displayed when the user selects the CD-ROM icon and right-clicks the mouse.

The smallest autorun.inf file contains three lines of text and identifies the startup application and the icon for the CD-ROM:

[autorun]

open=filename.exe

icon=filename.ico

The [autorun] line identifies the following block of lines as AutoPlay commands. This line is required in every autorun.inf file. The open=filename.exe line specifies the path and filename of the application that AutoPlay runs when the user inserts the CD into an appropriate drive. The icon=filename.ico line specifies an icon to represent the AutoPlay-enabled CD in the Windows 95 user interface.


Tips for Writing AutoPlay Applications

  Introduction

  Opening a Startup Application

  Loading in the Background

  Conserving Hard Disk Space

  Using the Registry

  Setting the NoDriveTypeAutoRun Value


Tips for Writing AutoPlay Applications

AutoPlay is a simple, yet powerful, feature. The following guidelines provide some information to ensure that AutoPlay will work well with your applications.


Opening a Startup Application

Most users need instant feedback when they insert an AutoPlay CD. You can accomplish this by using the open command of the autorun.inf file to open a small startup executable (.exe) file that loads very quickly. The startup application should include the following features:

•	Quick feedback to the user.

•	Clear identification of the title to be played.

•	Simple cancellation.


Loading in the Background

Generally, users will choose OK in the dialog box of the startup application. Take advantage of this by starting another thread that loads the setup application in the background before the user chooses OK. This significantly reduces the perceived load time for your application.


Conserving Hard Disk Space

Hard disk space is a limited resource. Here are a few tips that conserve hard disk usage:

•	Run the application from the CD-ROM directly, without running any installation program.

•	If your application needs to use the hard drive, install only the functional components necessary to run the application, and provide an uninstall function that removes the application from the hard disk. For more information about uninstalling an application, see the documentation included with the Microsoft Win32 Software Development Kit (SDK).

•	If your application needs to use the drive as a data cache, provide the user with options in the startup application that will enable the cached data to be discarded when quitting the title or game.


Using the Registry

The registry is a feature of Windows 95 that supersedes initialization (.ini) and application configuration files. For more information about registry manipulation application programming interfaces (APIs), see the documentation included with the Microsoft Win32 SDK.

If your title records and uses initialization information, you can use the registry to store and retrieve this information. The startup application can use the information (or lack of information) in the registry to identify whether the product needs to be installed:

•	If your product is used for the first time (no registry entries), present a dialog box that lists the setup options.

•	If the product is installed (listed in the registry), present a dialog box with just the OK and Cancel buttons.

For debugging purposes, you can enable a machine to read the autorun.inf file from a floppy drive by changing the system registry. Use the following procedure to do this:

1.	Use the REGEDIT tool to search for the string “auto”.

The results of the search should be in the HKEY_CURRENT_USER key under the following subkey:

\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

2.	Change the data of the NoDriveTypeAutoRun value from 0000 95 00 00 00 to 0000 91 00 00 00.

This change enables AutoPlay (that is, reading the autorun.inf file) on any drive; however, you must select AutoPlay when working with a floppy disk to run the startup application. You can double-click the icon of the floppy disk, or select the icon of the floppy disk and access the shortcut menu to start AutoPlay.

3.	After completing your tests of autorun.inf, reset the value of NoDriveTypeAutoRun to 0000 95 00 00 00.

Important

The capability of implementing AutoPlay on floppy disks is provided solely to help programmers debug their autorun.inf files before burning the CD. AutoPlay is intended for public distribution on CD only.

There is an inherent danger of this technique being used to spread viruses via floppy disks. Therefore, it is appropriate to suspect that any publicly distributed floppy disks that contain autorun.inf files are contaminated.


Setting the NoDriveTypeAutoRun Value

The NoDriveTypeAutoRun value in the registry is a four-byte binary data value of the type REG_BINARY. The first byte of this value represents different types of drives that can be excluded from working with AutoPlay.

The initial setting for the first byte of this value is 0x95 that excludes the unrecognized type drive, DRIVE_UNKNOWN, DRIVE_REMOVEABLE, and DRIVE_FIXED media types from being used with AutoPlay. You can enable a floppy disk drive for AutoPlay by resetting bit 2 to zero (or by specifying the value 0x91 to maintain the rest of the initial settings). A table identifying the bits, bitmask constants, and a brief description of the drives follows:

Bit number	Bitmask constant	Description
0 (low-order bit)	DRIVE_UNKNOWN	Drive type not identified.
1	DRIVE_NO_ROOT_DIR	Root directory does not exist.
2	DRIVE_REMOVEABLE	Disk can be removed from drive (that is, a floppy disk).
3	DRIVE_FIXED	Disk cannot be removed from drive (that is, a hard drive).
4	DRIVE_REMOTE	Network drive.
5	DRIVE_CDROM	CD-ROM drive.
6	DRIVE_RAMDISK	RAM disk.
7 (high-order bit)		Reserved for future use.


Suppressing AutoPlay

You can bypass the AutoPlay feature by holding down the SHIFT key when inserting a CD. This prevents autorun.inf from being parsed and carried out.


AutoPlay for MS-DOS–Based Applications

AutoPlay can also be used to install, configure, and run MS-DOS–based applications in a Windows 95 MS-DOS session. Each MS-DOS–based application can be configured with its own unique icon, config.sys file, and autoexec.bat file.

Windows 95 creates correct configuration files for an MS-DOS–based application. The startup application can then cause the MS-DOS–based application to start within a window. it can even cause Windows 95 to effectively restart to run the application if necessary and immediately return to Windows when the application closes.


defaulticon

defaulticon=path\iconname.ico

Specifies an absolute path on the CD to locate the icon that represents the AutoPlay-enabled CD in the Windows 95 user interface.

path/iconname.ico

Absolute path and filename of the file containing the icon. You can also specify a .bmp, .exe, or .dll file. If a file contains more than one icon, specify the resource number (index) of the icon in the file to use.

If both icon and defaulticon commands are present in an autorun.inf file, AutoPlay uses the icon specified in the defaulticon command.

When the drive does not contain an AutoPlay-enabled CD, the system uses a default icon in its place.


icon

icon=filename.ico

Specifies an icon to represent the AutoPlay-enabled CD-ROM in the Windows 95 user interface. The filename specified with this command must be located in the same directory as the filename specified by the open command.

filename.ico

Name of the file containing the icon. You can also specify a .bmp, .exe, or .dll file. If a file contains more than one icon, specify the resource number (index) of the icon in the file to use.

When the drive does not contain an AutoPlay-enabled CD, the system uses a default icon in its place.

The following example specifies the second icon in a file to represent a CD. (The index of the first icon is zero).

icon=filename.exe 1


open

open=dir\filename.exe

Specifies the path and filename of the application that AutoPlay runs when the user inserts the CD into a CD-ROM drive.

dir\filename.exe

Path and filename of any executable file to run or document to open when the CD is inserted. If no path is specified, Windows 95 looks for the file in the root of the CD. You can specify a relative path to locate the file in a subdirectory.

If the file is a document, Windows 95 starts the application associated with the specified document.

You can also include command-line parameters that AutoPlay passes to the program upon execution.

Use this command to open a startup application that provides instant feedback for the user. For more information about startup applications, see Opening a Startup Application.


shell

shell=verb

Changes the default entry of the shortcut menu to the specified custom command.

verb

Abbreviated form of a custom command. The custom command must be defined in the autorun.inf file.

AutoPlay is the default menu item defined for any AutoPlay-enabled disk.

When the user double-clicks on the icon for your CD, the command associated with verb is carried out.


shell\verb

shell\verb\command=filename.exe

shell\verb=Menu Item Name

Specifies a custom command listed in the shortcut menu for the icon. The first line identifies the executable file that performs the command. The second line specifies the custom entry of the shortcut menu.

verb

Abbreviated form of the command. This parameter associates a command with the executable filename and the menu item. This parameter must not contain embedded spaces.

Users will not see verb unless Menu Item Name is omitted from autorun.inf.

filename.exe

Filename of the application that performs the custom command.

Menu Item Name

Menu item text that can contain mixed case letters and spaces. You can also set an accelerator for the menu item by preceding one of the letters in the item with an ampersand.

When users point to an icon in the Windows 95 user interface and click the right mouse button, Windows 95 presents a shortcut menu for that icon. If an autorun.inf file is present on a CD, Windows 95 automatically adds “AutoPlay” to the shortcut menu, and sets it as the default behavior  double-clicking the icon will carry out whatever is specified in the open command.

To add the command Read Me to the shortcut menu for your product, include the following in autorun.inf:

shell\readit\command=notepad abc\readme.txt

shell\readit=Read &Me