hta/javascript如何执行具有相对路径的应用程序 [英] hta/ javascript How to execute an application with relative path

查看:140
本文介绍了hta/javascript如何执行具有相对路径的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个.hta(使用javascript),我想从中启动几个应用程序.

I'm building a .hta (with javascript) from which i want to launch several applications.

但是当我执行.hta时,出现错误消息找不到文件

But when i execute my .hta i get the error message can't find file

这是代码:

<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>

推荐答案

window.location.href也包括文件名和协议.试试这个:

window.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('/') + '/';

注意使用/代替\,并且以/结尾的relpath也很方便,因此您无需将其添加到函数参数中.

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.

编辑

我不确定您要获取没有文件的位置是什么意思,也许这是(来自Windows Sripting Technologies的引文(不幸的是现在被打破了):

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."

活动进程是例如正在运行的HTA,因此这将提供HTA文件的本地路径(不带文件名).

The active process is for example the running HTA, so this will give the local path of the HTA file (without filename).

currentDirectoryWScript.Shell的属性,因此您可以将其与代码中的WshShell一起使用,还可以设置工作目录.

currentDirectory is a property of WScript.Shell, so you can use it with WshShell in your code, also to set working directory.

这篇关于hta/javascript如何执行具有相对路径的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆