使用 Javascript 运行批处理文件 - Firefox

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27982245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:14:55  来源:igfitidea点击:

Running Batch file using Javascript - Firefox

javascriptfilebatch-file

提问by Vivek

This is important for me as I have a PRN file which can be printed only through command prompt. And I want to delete that file after the print command is given.

这对我很重要,因为我有一个只能通过命令提示符打印的 PRN 文件。我想在给出打印命令后删除该文件。

So these 2 commands can be executed using batch file only.

所以这两个命令只能使用批处理文件执行。

And when I try to use activexobject in javascript, my firefox browsers doesnt run it.

当我尝试在 javascript 中使用 activexobject 时,我的 firefox 浏览器不会运行它。

<script>
MyObject = new ActiveXObject("WScript.Shell");
function Runbat()
{
MyObject.Run("\"D:\abc.bat\"");
}
</script>

回答by Luca

Together in a html page.

一起在一个html 页面中

I've found this one and it seems working properly :)

我找到了这个,它似乎工作正常:)

<html>
    <head>
        <script language="JavaScript" type="text/javascript">
            MyObject = new ActiveXObject("WScript.Shell")
            function Runbat()
            {
                MyObject.Run("\"D:\test.bat\"");
            }
        </script>
    </head>
    <body>
        <h1>Run a Program</h1>
        This script launch the file any bat File<p>
        <button onclick="Runbat()">Run bat File</button>
    </body>
</html>

Now I don't really know if you are already working with exaclty that solution, if so, and you are still facing this issue in firefox you may need to investigate a little bit more in browser security to know if that is even possible as of this poststates that:

现在我真的不知道您是否已经在使用该解决方案,如果是这样,并且您仍然在 Firefox 中面临这个问题,您可能需要在浏览器安全性方面进行更多调查,以了解这是否可行这篇文章指出:

No, that would be a huge security breach. Imagine if someone could run

format c:

whenever you visted their website.

不,那将是一个巨大的安全漏洞。想象一下如果有人能跑

format c:

每当您访问他们的网站时。