Question

We use HTA files to build installation CD's, so that we can display some introductory information and links to different setup options - each link goes to the appropriate setup.exe etc file. This has worked fine up to and including Windows 7, but on 8.1 (- not tried 8.0) it fails with an error 'Cannot find the file specified'. Turns out that this is because the current directory is now C:\Windows\System32, whereas it used to be the directory where the file was located - on the CD drive, and so relative paths would work for the links to the other files on the CD; now they don't.

In other words using this code in an hta file:

<script type="text/javascript" language="javascript">
    function RunFile(appname) 
    {
    WshShell = new ActiveXObject("WScript.Shell");
    alert( WshShell.CurrentDirectory );
    WshShell.Run(appname, 1, false);
    }

on win 8.1 we see C:\Windows\System32 in the alert box and so relative paths such as ..\ourproduct\setup.exe no longer work.

Is this a bug? Any ideas how I can work around this?

Was it helpful?

Solution

You could extract the correct path from window.location.pathname, and then set the value to CurrentDirectory. I've used something like the code below:

var shell = new ActiveXObject('WScript.Shell'),
    defaultInstallationFolder = 'installation_folder_name',
    currentPath = window.location.pathname.replace(/\\/g,'/'),
    defaultRootPath;
if (currentPath.charAt(0) === '/')  { // For the browser environment
    currentPath = currentPath.substring(1, currentPath.length);
}
currentPath = currentPath.split(defaultInstallationFolder);
defaultRootPath = currentPath[0] + defaultInstallationFolder;
shell.CurrentDirectory = defaultRootPath;

IE and HTA give a slightly different pathname (in IE it starts with /). Sometimes it's nice to debug a HTA in IE, hence the check for currentPath.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top