如何在我的Firefox扩展中运行本地exe文件?
问题描述:
我想在我的Firefox扩展JavaScript文件中运行本地exe文件,但ActiveXObject(“WScript.Shell”)在IE中正常工作,而不是在FF中,如何在Firefox中运行本地exe文件。如何在我的Firefox扩展中运行本地exe文件?
答
既然你已经明确要求为.exe,那么你可以使用nsILocalFile.launch()
: https://developer.mozilla.org/en/Code_snippets/Running_applications
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("c:\\myapp.exe");
file.launch();
如果你想让它跨平台的,你应该看看nsIProcess
答
大家好这些谁试图在Mozilla Firefox中使用JavaScript调用一个exe文件。按照步骤..我可以从我的网站运行EXE。
第1步。在地址栏中输入“about:config”并将“signed.applets.codebase-principal-support”设置为true。 第2步。使用此代码。
<html>
<head>
</head>
<body>
<p/><input type="button" width="15" value="Run Exe" onclick="RunExe();"/></input></p>
<script type="text/javascript">
function RunExe()
{
alert("In fun RunExe()..");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
alert("Done");
var exe = window.Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("c:\\WINDOWS\\notepad.exe");
alert("exe");
var run = window.Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = [""];
run.run(false, parameters,parameters.length);
alert("in function RunBat");
}
</script>
</body>
</html>
+0
这不会让任何网页调用任意可执行文件吗? – daveloyall 2014-11-05 15:18:24
您不应该只是粘贴一个链接,而是总结内容。如果将来链接断开,您的整个答案就不再有任何价值。 – McK 2016-06-02 10:29:29
@McK你是绝对正确的。 – pawel 2016-06-02 10:58:34
'Components.classes'无法通过运行在网页上的JavaScript访问,只能通过运行在Firefox扩展中的JavaScript访问 – NPE 2016-10-25 02:47:17