HOW TO: Create an Autorun CD-ROM for Applications That You Create by Using Microsoft Visual Studio .NET


This step-by-step article describes how to create Autorun-enabled CD-ROMs for Microsoft Visual Studio .NET applications. Autorun is a feature of the Microsoft Windows operating system. It automates the procedures for installing and configuring products that are designed for Windows-based computers and are distributed on CD-ROMs. When a user inserts an Autorun-enabled CD-ROM in the CD-ROM drive, Autorun automatically runs an application on the CD-ROM that installs, configures, or runs the selected product. To create an Autorun-enabled CD-ROM for your Visual Studio .NET application, the following files must exist on the CD-ROM:
  • An Autorun.inf file
  • Startup application
When a user inserts a disc in a CD-ROM drive on an Autorun-compatible computer, the system immediately verifies that the disc has a personal computer file system. If it exists, the system searches for a file named Autorun.inf. This file specifies a setup application and a variety of optional settings. Typically, the startup application installs, removes, configures, and possibly runs the application. Visual Studio .NET applications require the .NET Framework to be installed on the computer where the application runs. The .NET Framework Redistributable Package can be used if the computer does not have the .NET Framework installed.

back to the top


The destination computer must meet the following requirements for Autorun to work:
  • The operating system of the computer must be Microsoft Windows 95 or later.
  • The CD-ROM drive must have 32-bit device drivers that detect when a user inserts a CD-ROM, and then notify the system.
back to the top

Create an Autorun.inf File

Autorun.inf is a text file that is located in the root folder of your application CD-ROM. It provides to the computer the name and the location of the startup program for your application that is installed when the CD-ROM is inserted. The Autorun.inf file can also contain optional information including the following:
  • The name of a file that contains an icon that represents your application's CD-ROM drive. This icon appears in Windows Explorer instead of the standard drive icon.
  • Additional commands for the shortcut menu that appears when the user right-clicks the CD-ROM icon. You can also specify the default command that runs when the user double-clicks the icon.
Autorun.inf files are similar to .ini files. They include one or more sections. Each section has a name that is enclosed in square brackets. Each section contains a series of commands that the Windows Shell runs when the user inserts the disc. The following two sections 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 CD-ROM is inserted in a CD-ROM drive on a RISC-based system, the Windows Shell runs the commands in this section instead of those in the [autorun] section.
Each section contains a series of commands that determine how the Autorun operation occurs. The following five commands are available:
  • defaulticon: Specifies the default icon for the application.
  • icon: Specifies the path and the file name of an application-specific icon for the CD-ROM drive.
  • open: Specifies the path and the file name of the startup application.
  • shell: Defines the default command in the shortcut menu of the CD-ROM.
  • shell\verb: Adds commands to the shortcut menu of the CD-ROM.
The following is an example of a simple Autorun.inf file. It specifies Filename.exe as the startup application. The second icon represents the CD-ROM drive instead of the standard drive icon.
back to the top

Tips for Writing Autorun Startup Applications

Essentially, there are no constraints on how to write an Autorun startup application. You can implement it to do whatever you require to install, remove, configure, or run your application. However, the following tips provide some guidelines for implementing an effective Autorun startup application:
  • Users should receive feedback as soon as possible after they insert an Autorun CD-ROM in the CD-ROM drive. Therefore, startup applications should 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) that prompts them for how they would like to proceed. Verify whether the program is already installed. If not, the next step is typically the setup procedure. The startup application can use the time that the user spends reading the dialog box to start another thread to start loading the setup code. When the user clicks OK, your setup program will already be partly or fully loaded. This approach significantly reduces the user's perception of the time that it takes to load your application.
  • If the application is already installed, the user probably inserted the disk to run the application. As with the setup case, you can start another thread to start loading the application code. This approach shortens the waiting time for the user.
  • The .NET Framework or the .NET Framework Redistributable Package must be installed on the destination computer to start your Visual Studio .NET application. Therefore, it is a good idea to redistribute the .NET Framework with your startup application.
    For additional information about how to distribute the .NET Framework with a Visual Studio .NET application, click the following article number to view the article in the Microsoft Knowledge Base:
    324733 HOW TO: Distribute the .NET Framework with a Visual Studio .NET Deployment Project
  • Hard disk space may be a limited resource on many systems. The following are hints to minimize hard disk usage:
    • Keep the number of files that must be on the hard disk to a minimum. Restrict these to files that must be installed to run the program or that take an unacceptably long time to read from the CD-ROM.
    • In many cases, you do not have to install nonessential files on the hard disk. However, this approach may provide benefits such as increased performance. Give the user the option to decide between the costs and the benefits of hard disk storage.
    • Include a method to remove any components that were put on the hard disk.
    • If your application caches data, give the user some control over it. Include options in the startup application such as the option to set a limit on the maximum amount of cached data that will be stored on the hard disk, or the option to have the application discard any cached data when it quits.
back to the top

Step-by-Step Example

  1. Start Visual Studio .NET.
  2. Create a simple Console Application or Windows Application.
  3. Build the application.
  4. On the File menu, point to
    New, and then click Project.
  5. In
    Project Types, click Setup and Deployment Projects. In Templates, click Setup Projects.
  6. Name the project Setup, and then click
  7. In Solution Explorer, right-click your Setup project, click Add, and then click
  8. In the File name text box, type the absolute path of the executable that you built in step3, and then click
  9. On the Build menu, click Build Solution.
  10. Start any text editor (such as Notepad).
  11. Paste the following code in the text editor, and then save the file as Autorun.inf:
  12. To prepare an Autorun CD-ROM for the Visual Studio .NET application that you built in step 3, copy the files that were generated in step 9 and the Autorun.inf file that you created in step 11 to the CD-ROM.
back to the top


For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
172078 HOWTO: Enable Autorun for Applications Distributed on CD- ROM
136214 How to Test Autorun.inf Files
BUG #: 7796 (Content Maintenance)

back to the top

Article ID: 818804 - Last Review: May 13, 2008 - Revision: 1