gpt4 book ai didi

javascript - 使用 WScript.shell activeX 在 javascript 中执行命令行

转载 作者:行者123 更新时间:2023-11-28 08:26:15 25 4
gpt4 key购买 nike

我正在尝试使用 shell 脚本执行命令行,以下面的代码为例

function callShellApp() {
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"c:\menu.exe"');
}

根据我的要求,objShell.run 应该处于同步模式,除非发生这种情况,否则我应该允许用户导航屏幕。有没有办法可以做到这一点来维持这一点。

最佳答案

据我所知,使用 JS 不可能完全同步执行外部源,这里有一个“半同步”调用的代码片段:

objShell.Run('"c:\\menu.exe"', 1, true);
// JS after the line above is not executed until menu.exe has been terminated

注意也转义了反斜杠。虽然 JS 会等待,但页面本身是响应式的。为了防止页面和用户之间的交互,您可以执行以下操作:

top.addEventListener('focusin', function () {
objShell.AppActivate(apptitle); // apptitle === the title of the window wherein `menu.exe` is running
});

不幸的是,即使这样也不会阻止定时函数的执行。

menu.exe 完成之前关闭页面时,这也会造成问题。请参阅例如this answer ,如果发生这种情况如何关闭您的应用程序。

关于javascript - 使用 WScript.shell activeX 在 javascript 中执行命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22378067/

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