从 Javascript 运行 .exe [英] Running .exe from Javascript
本文介绍了从 Javascript 运行 .exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 Javascript 运行 .exe 文件.这就是我所拥有的:
I am trying to run a .exe file from Javascript. This is what I have:
var oShell = new
ActiveXObject("Shell.Application");
var commandtoRun = "C:Documents and
SettingsUserDesktopABCD.exe";
oShell.ShellExecute(commandtoRun,"","","open","1");
如果我只有前 2 行代码,它似乎工作正常(当我第一次在 IE 中打开它时它问我是否需要 activeX)但如果我添加最后一行(ShellExecute),似乎有错误.我想将参数传递给 exe.
If I have only the first 2 lines code it seems to work fine (it asked me do I want activeX when I opened it first time in IE) but if I add the last line (ShellExecute) there seems to be an error. I want to pass arguments to the exe.
有人知道怎么做吗?
推荐答案
你需要转义反斜杠,例如,
You need to escape the backslashes, e.g.,
var commandtoRun = "C:\Documents and Settings\UserDesktop\ABCD.exe";
更新:
这在我的机器上运行良好:
This works fine on my machine:
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\Windows\notepad.exe";
oShell.ShellExecute(commandtoRun,"","","open","1");
更新 2
您可以将其保存为扩展名为 .hta
的文件,它应该可以在您的浏览器中运行:
You can save this as a file with the extension .hta
and it should work in your browser:
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Application Executer"
BORDER="no"
CAPTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="no"
WINDOWSTATE="normal">
<script type="text/javascript" language="javascript">
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\Windows\notepad.exe";
oShell.ShellExecute(commandtoRun,"","","open","1");
</script>
这篇关于从 Javascript 运行 .exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文