To create an AutoPlay CD, you include an AUTORUN.INF file in the root directory of the CD in the following format:
[autorun]
OPEN=<executable program to run>
ICON=<icon to show in Windows Explorer>
If you don't have an icon to display, you can omit the
ICON entry. The AutoPlay feature in Windows doesn't call the Win32
ShellExecute() API, so you're limited to
.exe,
.com or
.bat files for the
OPEN entry. That's a problem, because you want to launch a
.HTA file. Fortunately, the solution is relatively simplecreate a short EXE program that calls
ShellExecute(). The
AUTORUN.EXE program included with the sample calls
ShellExecute() for you, so it can launch an HTA file.
The sample
AUTORUN.EXE stub program accepts a single command-line argumentthe name of the file to run, so if you wanted to the launcher to start an
autorun.hta application, your
AUTORUN.INF file would look like this:
[autorun]
OPEN=autorun.exe autorun.hta
If the
ShellExecute() function returns an error (as it would if the target computer doesn't have Internet Explorer 5 or greater), the autorun stub opens the CD root directory in Windows Explorer.
Listing 1 shows the the
AUTORUN.EXE source code. You don't need a C compiler to use the sample code unless you want to modify the Autorun.exe program itself.