从Javascript运行.exe [英] Running .exe from Javascript

查看:105
本文介绍了从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
Settings\User\Desktop\ABCD.exe;
oShell.ShellExecute(commandtoRun,,,open,1);

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\Documents and Settings\User\Desktop\ABCD.exe"; oShell.ShellExecute(commandtoRun,"","","open","1");

如果我只有前两行代码似乎工作正常(它问我在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\\User\Desktop\\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屋!

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