CD Autorun for HTML File

When a CD is inserted into a PC, Windows looks for a file called autorun.inf. This file can contain many options, but at its simplest it just tells Windows to run a command, as in the example below:

[autorun]
open=program.exe

You can insert any command you like into this file, and once the requested command is in the PATH environment variable, it will run.

Opening a HTML file.
In order to open a data file, such as a HTML file, automatically, the autorun.inf needs to call the Windows Start command. Running a command such as start index.html should run the application associated with HTML files and open index.html within that application. You would think that a simple autorun.inf like this would do the trick:

[autorun]
open=start index.html

However, this doesn't seem to work in most cases. So we have developed a really simple application that passes on your requested parameters to Windows, and can be used to start any program when a CD is inserted. This simple, free program, called RunCmd can be downloaded using this link:

http://cdrunner.50webs.com/downloads/RunCmd.zip

Once you have downloaded the Zip file (4Kb), unpack the executable file (7Kb) and place it in the root of your CD file structure when you are burning your CD.

Then, to get that CD to automatically open a HTML file, you need to copy the autorun.inf to the root folder of the CD, alongside the RunCmd.exe. This autorun.inf file should contain the command to tell RunCmd.exe to open the HTML file:

[autorun]
open=RunCmd.exe start index.html

You can change the text index.html in the autorun.inf file to the name of the file you want to open automatically, including its relative path if it is not in the root folder. This will then automatically open the required file when the CD is inserted into a Windows PC.

The RunCmd.exe utility is an extremely simple, ANSI C program of about 30 lines. I am copying below the source code (C File), can compile and used instead of downloading zip file.

#include "stdio.h"
#include "string.h"

#define MAX_CMD_SIZE 128

int main(int argc, char* argv[])
{
char cmdStr[MAX_CMD_SIZE];
int i = 1;
cmdStr[0] = 0;

while(i < argc)
{
if((strlen(cmdStr) + strlen(argv[i]) + 1) < MAX_CMD_SIZE)
{
strcat(cmdStr, argv[i]);
strcat(cmdStr, " ");
}

i++;
}

printf("Executing command: \"%s\"", cmdStr);

if(strlen(cmdStr))
{
system(cmdStr);
}

return 0;
}

Read Users' Comments (0)

0 Response to "CD Autorun for HTML File"

Post a Comment