admin管理员组文章数量:1416651
I'm building a .hta (with javascript) from which i want to launch several applications.
But when i execute my .hta i get the error message can't find file
this is the code:
<script type="text/javascript" language="javascript">
function RunFile(path) {
var relpath = window.location.href;
var fullpath = relpath + path;
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run(fullpath, 1, false);
}
RunFile("\file.exe");
</script>
I'm building a .hta (with javascript) from which i want to launch several applications.
But when i execute my .hta i get the error message can't find file
this is the code:
<script type="text/javascript" language="javascript">
function RunFile(path) {
var relpath = window.location.href;
var fullpath = relpath + path;
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run(fullpath, 1, false);
}
RunFile("\file.exe");
</script>
Share
Improve this question
asked Dec 12, 2012 at 15:55
user1644062user1644062
651 silver badge5 bronze badges
1 Answer
Reset to default 5window.location.href
includes filename and protocol too. Try this:
var relpath = window.location.pathname.replace(/\\/g,'/').split('/');
relpath.pop();// JScript: relpath.length = relpath.length - 1;
relpath = relpath.join('/') + '/';
Notice use of /
instead \
, and it's also handy to end up relpath
with /
, so you don't need to add it to function argument.
EDIT
I'm not sure what you mean with getting location without file, maybe this (citation from Windows Sripting Technologies (unfortunately broken now):
"The CurrentDirectory returns a string that contains the fully qualified path of
the current working directory of the active process."
The active process is for example the running HTA, so this will give the local path of the HTA file (without filename).
currentDirectory
is a property of WScript.Shell
, so you can use it with WshShell
in your code, also to set working directory.
本文标签: htmlhta javascript How to execute an application with relative pathStack Overflow
版权声明:本文标题:html - hta javascript How to execute an application with relative path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745256122a2650113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论