简体   繁体   English

从 Javascript 运行 .exe

[英]Running .exe from Javascript

I am trying to run a .exe file from Javascript.我正在尝试从 Javascript 运行 .exe 文件。 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");

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.如果我只有前 2 行代码,它似乎工作正常(当我第一次在 IE 中打开它时它问我是否需要 activeX)但如果我添加最后一行(ShellExecute),似乎有错误。 I want to pass arguments to the exe.我想将参数传递给 exe。

Does anyone know how to do it ?有谁知道怎么做?

You need to escape the backslashes, eg,您需要转义反斜杠,例如,

var commandtoRun = "C:\\Documents and Settings\\User\Desktop\\ABCD.exe";

Update:更新:

This works fine on my machine:这在我的机器上运行良好:

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Windows\\notepad.exe"; 
oShell.ShellExecute(commandtoRun,"","","open","1");

Update 2更新 2

You can save this as a file with the extension .hta and it should work in your browser:您可以将其保存为扩展名为.hta的文件,它应该可以在您的浏览器中运行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM