Can Johnny Come Out to AutoPlay?

Windows 95 executes your application off a CD-ROM

Robert Hess

May 9, 1995

OK, picture this. You are sitting at your computer and suddenly get the itch to play a game. You have the latest CD-ROM version of <your favorite game>, and you push the disc into your CD-ROM drive. What is the next thing you want to do?

Simple. Play the game. What steps are necessary to do this? Not so simple. Depending on exactly how the CD-ROM and its application were designed, you may face such instructions as:

1. Insert the CD into your CD-ROM drive.

2. With Windows running, from Program Manager, select the File menu, and then the Run command.

3. In the Run dialog box, either type the full path of the application to run (d:\game\full\game.exe, assuming that your CD-ROM drive is the D drive; enter the appropriate drive letter if your CD-ROM drive is located elsewhere) or click the Browse button and navigate your way to the GAME.EXE application.

Since one of the primary goals of Windows 95 is "Make it easy, not just easier," this is obviously an aspect of the system that could vastly improve. To make this "easy" you want the game to start automatically when you insert the CD. On Windows 95, this is exactly what can happen.

A new feature, AutoPlay, allows Windows 95 to automatically start your application off a CD-ROM as soon as the disc is inserted into the drive. It makes playing a CD-ROM–based game on Windows 95 as easy as playing a game on a standard cartridge-based game system.

Implementing AutoPlay support

If you are developing an application to be distributed on CD-ROM, you should seriously consider adding AutoPlay support to your disc. It doesn't require any programming knowledge or changes to your application, and it is completely backward compatible with any system on which your CD-ROM currently runs.

All you need do to implement AutoPlay on your CD title is add a file named AUTORUN.INF to the root of your CD-ROM drive. When the CD is inserted into the drive, the system automatically looks for this file and follows the instructions in it.

The format of AUTORUN.INF is similar to a standard .INF or .INI file, with a section name (enclosed in square brackets) followed by keywords and values on subsequent lines. A minimum AUTORUN.INF file would look like:

[autorun]

open = filename.exe

In this example, autorun is the required section name; open is the keyword the system will seek to determine what action to take when the CD is inserted; and filename.exe is the application that will be started.

A fully configured AUTORUN.INF file might look like:

[autorun]

open = filename.exe /switch1 /switch2

icon = filename.exe, 1

shell\configure = &Configure

shell\configure\command = setup.exe /config

shell\install = &Install

shell\install\command = setup.exe

shell\readme = &Read Me

shell\readme\command = notepad

help\readme.txt

shell\help = &Help

shell\help\command = help\helpfile.hlp

In addition to automatically launching filename.exe, the above example will add two command-line parameters, /switch1 and /switch2, when the application is run. The actual command-line parameters to use, of course, depend on what the application being launched accepts. When the drive is viewed in the Explorer (a Windows 95 navigational tool that replaces Program Manager and helps you locate files and information), the second icon in the executable's resource will be used in place of the normal CD-ROM icon (icon references are zero-based). If you would rather access the icon by its ID, simply use the negative ID value.

When the user clicks the icon with the right mouse button, four new items can appear—Configure, Install, Read Me, and Help—in addition to the normal context menu items. The user clicks the menu item to run the associated command. These menu items are used for illustration only, and are not intended as a recommendation of menu items you should add for your application. Please refer to the Windows User Interface Design Guide for Windows 95 to determine the best menu items to add for your application.

Suppressing AutoPlay

For those times when the user doesn't want to use AutoPlay when inserting an AutoPlay-enabled CD-ROM, it can easily be suppressed by holding down the SHIFT key while inserting the CD.

AutoPlay style guidelines

While there isn't yet much in the way of style guidelines on implementing AutoPlay, here are some general rules of thumb to consider:

• Whatever you do, do it quickly, then stand back and let the user drive. Promptly give the user input on his or her wishes, whether it's to run the application, access some data, or do an about-face and exit.

• Use a minimum of hard-disk resources; run completely off the CD if at all possible.

• If there is a performance benefit in loading some data onto the hard drive, let the user select this option.

• If data is moved to the hard drive, have it removed upon exiting.

• If the application can be fully installed to the hard drive, provide this as an option to the user. But provide the option to fully remove it from the hard drive as well.

Further information

A very simple application illustrating how an AutoPlay-enabled application might be implemented—"Building AutoPlay-Enabled CD-ROM Titles and Games" by Alex St. John and Jeff Camp—can be found in the Technical Articles section of the April release of the Developer Network Development Library. It takes a very simple application and, rather than running it directly when the CD is inserted, runs a 'launcher' application that quickly allows the user either to launch the application or exit.

Robert Hess works in the Developer Relations Group, where he spends his time huddled behind several computers, trying to influence application developers worldwide.