View Full Version : Launching Docs in hta:application

07-18-2004, 03:24 AM
I've been trying to map out what I want. Being very new to JavaScripting I've really started to struggle so I am hoping someone can help me out here.

The javascript is being used for an application I orginally wrote as an interface in html. Now I am trying to find ways to get it to work in an hta:application and be a bit more smarter in its handling of how to launch a document.

Is someone able to please help me out with filling in the code?
I know its a big ask, any help is appreciated.


<script language="JavaScript">

/* Purpose of the script is to launch a word document an application that can support it's type
This script is being run in hta:application - When launching direction from an hta it
displays in browser and looks like gobblygook.
Q: Is there a way to just have hta handle the launch according to preset file associated with it?
Ideally this will launch the application and not house the application within the browser like it would in an html

/* WhereWord = Need to determine if WinWord.exe Exsists in standard install locations
Current known standard install locations
var OldWord = C:\\Progra~1\\Micros~1\\Office\\WinWord.exe
var NewWord = C:\\Progra~1\\Micros~2\\Office10\\WinWord.exe
Whereword will be set to equal the file path found to exsist (be true).

I took view because I couldn't find a way to truncate a where exsists

/* varFilename = Value submitted onClick in document window.
This value needs to have .doc added to it as a file extension

/* When WhereWord Exsists the following must be performed
Launch WinWord varFilename .doc in maximsed state %1

/* Perform a browse for application to open document in and set that as default for this application

/* Perform an alert when a suitable .doc application not exsist.


In html
<a href="#" return OnClick="Launch()" value="F01">F01</a>

07-19-2004, 01:15 AM
Are you saying that you'd like to open a .doc in Word (if available) and if not, allow the user to browse for an application to open the .doc in (and then save that preference)?

07-19-2004, 03:23 AM
It would seem that determining a default application is unnecessary, because the ShellExecute Method (http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/ishelldispatch2/shellexecute.asp) of the IShellDispatch2 Object (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/ishelldispatch2/ishelldispatch2.asp) can open a file in its default app...

For a full explanation of shell objects and methods, go here: Shell Objects for Scripting and Microsoft Visual Basic (http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/objects.asp).
If you have to determine the default app (for some reason), something like this would work:

<title>Default Application</title>
<script type="text/jscript">
function showPath(ext, out)
out.value = "";
var wShell = new ActiveXObject("Wscript.Shell");
/^"([^"]+)"/.test(wShell.RegRead("HKCR\\" + wShell.RegRead("HKCR\\" + ext + "\\") + "\\shell\\open\\command\\"));
return alert(e.message);
var path = RegExp.$1;
if(path == "null")
return out.value = "Executable path not available for this type.";
out.value = path;
<style type="text/css">
<label> Enter a file extension: </label>
<input name="ext" size="6" value=".doc">
<div style="padding-left:9em;margin-top:1em">
<input type="button" value="Get Path" style="font-weight:bold" onclick="showPath(ext.value, out)">
<label>output: </label>
<input style="width:100%" name="out" readonly>

07-19-2004, 05:17 AM
Yes, to your first query.

Now off reading about ShellExecute Method thanks to your pointers due to your second reply.

Thank you very much for taking the time to answer.

07-19-2004, 06:30 AM
About that example I gave:
the regular expression is not reliable for many default command strings... (it was just a quick test). ;)

Also, if the MSDN examples seem vague, feel free to ask for clarification, here.

07-19-2004, 10:47 AM

why use Shell commands when ActiveX is wot is usually used? more precisely, why create an ActiveX object to WSH shell and not to Word itself?


07-19-2004, 11:26 AM
Because, if Word is not installed, there is no automation object for it, so you'd need to have a try-catch fall-back to the Shell object (and there's no need for the whole Word OLB, just to open a .doc).

The WScript.Shell object is not required; that was just to demonstrate how one might query the registry for such information.

The Shell.Application object is part of a seperate interface from WSH, fyi.