Creating an AutoRun-Enabled Application

Creating an AutoRun-enabled application is a straightforward procedure. This topic uses CD-ROM as an example (it was the first medium to implement this technology) but today there are many different media types that can use it.

To enable AutoRun in your application, you simply include two essential files:

  • An Autorun.inf file
  • A startup application

When a user inserts a disc into a CD-ROM drive on a AutoRun-compatible computer, the system immediately checks to see if the disc has a personal computer file system. If it does, the system searches for a file named Autorun.inf. This file specifies a setup application that will be run, along with a variety of optional settings. The startup application typically installs, uninstalls, configures, and perhaps runs the application.

  • Creating an Autorun.inf File
  • The [DeviceInstall] Section
  • Tips for Writing AutoRun Startup Applications
  • Related Topics

Creating an Autorun.inf File

Autorun.inf is a text file located in the root directory of the CD-ROM that contains your application. Its primary function is to provide the system with the name and location of the application's startup program that will be run when the disc is inserted.

Note  Autorun.inf files are not supported under Microsoft Windows XP for drives that return DRIVE_REMOVABLE from GetDriveType.

The Autorun.inf file can also contain optional information including:

  • The name of a file that contains an icon that will represent your application's CD-ROM drive. This icon will be displayed by Windows Explorer in place of the standard drive icon.
  • Additional commands for the shortcut menu that is displayed when the user right-clicks the CD-ROM icon. You can also specify the default command that is run when the user double-clicks the icon.

Autorun.inf files are similar to .ini files. They consist of one or more sections, each headed by a name enclosed in square brackets. Each section contains a series of commands that will be run by the Shell when the disc is inserted. There are two sections that are currently defined for Autorun.inf files.

  • The [autorun] section contains the default AutoRun commands. All Autorun.inf files must have an [autorun] section.
  • An optional [autorun.alpha] section can be included for Microsoft Windows NT 4.0 systems running on RISC-based computers. When a disc is inserted in a CD-ROM drive on a RISC-based system, the Shell will run the commands in this section instead of those in the [autorun] section.

Note  The Shell checks for an architecture-specific section first. If it does not find one, it uses the information in the [autorun] section. After the Shell finds a section, it ignores all others, so each section must be self-contained.

Each section contains a series of commands that determine how the Autorun operation takes place. There are five commands available.

Command Description
defaulticon Specifies the default icon for the application.
icon Specifies the path and file name of an application-specific icon for the CD-ROM drive.
open Specifies the path and file name of the startup application.
useautorun Specifies that Autoplay V2 features should be used if supported.
shell Defines the default command in the CD-ROM's shortcut menu.
shell_verb Adds commands to the CD-ROM's shortcut menu.

The following is an example of a simple Autorun.inf file. It specifies Filename.exe as the startup application. The second icon in Filename.exe will represent the CD-ROM drive instead of the standard drive icon.


[autorun] 
open=Filename.exe 
icon=Filename.exe,1 
                

This Autorun.inf sample runs different startup applications depending on the type of computer.


[autorun] 
open=Filename_x86.exe 
icon=IconFile.ico 

[autorun.alpha] 
open=Filename_RISC.exe 
icon=IconFile.ico 
                

The [DeviceInstall] Section

You can use the [DeviceInstall] section on any removable media. It is supported only under Windows XP. You use DriverPath to specify a directory path where Windows XP searches for driver files, which prevents a lengthy search through the entire contents.

You use the [DeviceInstall] section with a driver installation to specify directories where Windows XP should search the media for driver files. Under Windows XP, entire media are no longer searched by default, therefore requiring [DeviceInstall] to specify search locations. The following are the only removable media that Windows XP fully searches without a [DeviceInstall] section in an Autorun.inf file.

  • Floppy disks found in drives A or B.
  • CD/DVD media less that 1 gigabyte (GB) in size.

All other media must include a [DeviceInstall] section for Windows XP to detect any drivers stored on that media.

Note  As with the [AutoRun] section, the [DeviceInstall] section can be architecture-specific.

Tips for Writing AutoRun Startup Applications

There are essentially no constraints on how to write an AutoRun startup application. You can implement it to do whatever you find necessary to install, uninstall, configure, or run your application. However, the following tips provide some guidelines to implementing an effective AutoRun startup application.

  • Users should receive feedback as soon as possible after they insert an AutoRun compact disc into the CD-ROM drive. Startup applications should thus be small programs that load quickly. They should clearly identify the application and provide an easy way to cancel the operation.
  • Typically, the initial part of the startup application presents users with a user interface, such as a dialog box, asking them how they would like to proceed. Check to see if the program is already installed. If not, the next step will probably be the setup procedure. The startup application can take advantage of the time the user spends reading the dialog box by starting another thread to begin loading the setup code. By the time the user clicks OK, your setup program will already be partly if not fully loaded. This approach significantly reduces the user's perception of the amount of time it takes to load your application.
  • If the application has already been installed, the user probably inserted the disk to run the application. As with the setup case, you can start another thread to begin loading application code to shorten the waiting time for the user.
  • Hard disk space may be a limited resource on many systems. Here are a few hints for minimizing hard disk usage:
    • Keep the number of files that must be on the hard disk to a minimum. They should be restricted to files that are essential to running the program or that would take an unacceptably large amount of time to read from the CD-ROM.
    • In many cases, installing nonessential files on the hard disk is not necessary, but may provide benefits such as increased performance. Give the user the option of deciding how to make the tradeoff between the costs and benefits of hard disk storage.
    • Provide a way to uninstall any components that were placed on the hard disk.
    • If your application caches data, give the user some control over it. Include options in the startup application such as setting a limit on the maximum amount of cached data that will be stored on the hard disk, or having the application discard any cached data when it terminates.
  • Even though a CD-ROM has an Autorun.inf file, AutoRun can be suppressed programmatically or disabled entirely with the registry. See Enabling and Disabling AutoRun for more information.
  • Writing a Device Installation Application