gpt4 book ai didi

javascript - hta/javascript 如何使用相对路径执行应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 15:31:14 24 4
gpt4 key购买 nike

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

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

这是代码:

<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 也包括文件名和协议(protocol)。试试这个:

var relpath = window.location.pathname.replace(/\\/g,'/').split('/');
relpath.pop();// JScript: relpath.length = relpath.length - 1;
relpath = relpath.join('/') + '/';

注意使用 / 而不是 \,并且用 / 结束 relpath 也很方便,所以您不需要将它添加到函数参数中。

编辑

我不确定你在没有文件的情况下获取位置是什么意思,也许是这个(来自 Windows Sripting Technologies 的引文(不幸的是现在已经损坏):

"The CurrentDirectory returns a string that contains the fully qualified path of
the current working directory of the active process."

例如,事件进程是正在运行的 HTA,因此这将给出 HTA 文件的本地路径(不带文件名)。

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

关于javascript - hta/javascript 如何使用相对路径执行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13843590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com