Autorun CD with html files on. Can specify browser?

Hi,

If I am making an auto-run CD for windows, can I specify which program should open the file? I want to autorun an index.html page and if possible force it to open in Inet Explorer rather than Netscape if they have that installed. I realise if I just autorun it will use whatever program is associated with the filetype, but this is what I want to override.

Anyone?

You’ll probably have to do this with a script. Here’s a javascript sample which looks up the path to IE and attempts to run it with the html page, but if that fails, just runs the html page with whatever browser it can. To use this, save it in a file called something like “browserlauncher.js” and have the CD autorun that. This will only work on machines with Windows Script Host, which is every recent version of windows, back to maybe Win98. Wouldn’t hurt to test it on a few different machines to make sure it’s good.



// Set startdoc to a quoted string which is the absolute path to
// your HTML document, omitting the drive designator.
// Note that backslashes must be escaped with another backslash, so path seperators are "\\"
var startdoc = "\\contents\\index.html"

var shell = WScript.CreateObject("WScript.Shell");

// LaunchDocInIExplore() looks for the reg key with the location of the iexplore executable,
// and if it finds it, launches it with the specified doc as a parameter.
//   Returns true if successful, false otherwise
function LaunchDocInIExplore(doc)
{
    var handler = shell.RegRead(
        "HKLM\\SOFTWARE\\Classes\\Applications\\iexplore.exe\\shell\\open\\command\\");

    if(!handler || handler == "")
        return false;

    var iepath = "";

    // if it's quotated, use the part in quotes.
    // if not, return the part up to the first space, quoted
    if(handler.charAt(0) == "\"")
    {
        var nextquote = handler.indexOf("\"", 1);
        var exename = handler.substr(0, nextquote+1);
        iepath = exename;
    }
    else
    {
        var splithandler = handler.split(" ");
        iepath = "\"" + splithandler[0] + "\"";
    }

    if(false && iepath && iepath != "")
    {
        var runstr = iepath + " \"" + doc + "\"";
        
        return (shell.Run(runstr) == 0);
    }

    return false;
}

// LaunchDoc() simply runs the doc, allowing the
// default handler for this file type to take over
function LaunchDoc(doc)
{
    shell.Run("\"" + doc + "\"");
}

if(!shell)
{
    WScript.Echo("Error creating WScript.Shell object.");
}
else
{
    // first try IE
    if(!LaunchDocInIExplore(startdoc))
    {
        // if that failed, just launch it
        LaunchDoc(startdoc);
    }
}


Note that this doesn’t require javascript to be enabled in the browser. The code will be executed by Windows Script Host.