http://www.chrispearson.org/pages/articles/autoplayCD.asp
09h33
Wednesday, 8. October 2008

Everyone
and her dog now seems to be burning CDs - from compilation
audio CDs through collections of software to games.
A key differentiator of data CDs is that most commercial
CDs autoplay when inserted (unless you've disabled autoplay!)
and homemade ones don't. |
How
to create a compact disc that
- has
a name
- has
an icon
- will
auto-start the user's default browser, displaying
your startup screen
|
|
|
| On
the downside, it can be tricky to get software to run on a
machine you've never seen, quite possibly running on operating
system that wasn't available when you cut the disc.
On the upside, browsers are now the common currency of all
systems (and operating systems) so you have immediate access
to presentation software of which you can be certain.
This
article covers how to create a CD that has an icon, a start-up
HTML page and options to run from its right-click, pop-up
menu.
You
can take advantage of the user's browser to display a welcome
screen, a menu or to start an entire application from a starting
HTML page. From that first page you can lead the user around
the CD, providing single-click links to files on the CD or
other resources. Just like a mini-web site, really.
Since you don't know in advance which browser is going to
be set as the user's default, it's necessary to force the
operating system to launch the right browser: You need to
do this without the luxury of being able to code
"C:\Program Files\Internet
Explorer\IEXPLORE.EXE" myHTML.htm
or equivalent - You don't know what browser it is or where
it's installed. |
|
| It's
relatively easy to set up the files which make a CD autoplay
a HTML page in a browser - To get started it doesn't require
any tools beyond a simple text editor like Notepad.
This
method has the advantage of requiring no programming in Visual
Basic or C++, or in VBScript. It does require a couple of
batch files but both of these can be used again and again
without modification, so long as your HTML file name remains
the same. The example described here - see The
files you'll need to include on the CD
- uses five files with reasonably reusable names. (OK - Icon.ico
would have been better. But less fun.) |
 |
| It
doesn't require any programming, either. If you always use files
with the same names you can change the content without worrying
about changing the file names you use. |
|
| HOW'S
IT DONE?
The
whole thing is driven by the two batch files, called Run_StartHTML.bat
and StartHTML.bat
and is tied together by the information in Autorun.inf,
as shown below.
The
contents of Autorun.inf are
[autorun]
open=Run_StartHTML.bat
ICON=smile.ico
cdname="AutoCD"
Using
two .bat files
is necessary to get Windows to force the file association
of an HTML file with a .htm
extension with the user's default browser.
Remember
that the HTML file is being opened from a file system and
not as a page server by a web server - You can't use any server-side
functionality: .ASP
pages are right out! |
The
files you'll need to include on the CD are
- An
autoplay information file called
autorun.inf
- Two
batch files which are the secret to getting this technique
to work: StartHTML.bat,
which runs the browser - but which we don't run directly
- and Run_StartHTML.bat
which does run StartHTML.bat!
- An
icon file with the name of your choice and a .ico
extension. For instance, smile.ico.
- An
HTML page which you create and give the name of your choice
with a .htm
extension. For instance, StartUp.htm.
- Any
image files you might want to include in the HTML page.
For example, ALogo.gif
and AnArrow.gif.
|
| |
There's
some background information to support this article in
Autoplay CDs - Background |
 |
|
How
to . . . summary
- Create
or find an icon and save it in the root folder of
the CD layout
- Create
the HTML page and save it in the root folder
- Add
the batch files to the root folder
- StartHTML.bat
- Run_StartHTML.bat
- Create
Autorun.inf and save it in the root folder
- Add
the rest of the CD contents
- Burn
the CD
- Test
it!
|
TESTING
STRATEGIES
 |
Tip
You
can set up Iomega Zip drives to autoplay - A Zip drive
can be used to emulate removeable media and save on
CDs during testing.
The
same applies to floppies but their capacity makes them
a poor emulator for a 600MB disc.
You
need to include all the appropriate autoplay files on
the removable disc - a floopy or a Zip disc - and the
enable autoplay for that device type.
Enabling
and disabling autoplay
The
autoplay parameters are stored in Windows' registry
and the only way I know to change these settings is
to edit the registry. (If you know another way, please
let me know!)
After
backing up, run regedit
and navigate down from the key HKEY_CURRENT_USER,
as here:
HKEY_CURRENT_USER\
Software\
Microsoft\
Windwos\
Current version\
Policies\
Explorer\
"NoDriveTypeAutoRun"
|
|
 |
| |
|
|
|
|
 |
NoDriveTypeAutoRun
is a four byte key but only the first byte is used as a bitmask:
| Type |
Bit |
| DRIVE_UNKNOWN |
0 |
| DRIVE_NO_ROOT_DIR |
1 |
| DRIVE_REMOVABLE |
2 |
| DRIVE_FIXED |
3 |
| DRIVE_REMOTE |
4 |
| DRIVE_CDROM |
5 |
| DRIVE_RAMDISK |
6 |
The
default is 0x95 which disables autoplay on every device type
bar the CD. |
|
|
|
copyright ©2000
-
2008 Chris Pearson