使用 javascript 运行 Apache 服务器中存在的批处理文件

Running a batch file present in Apache server using javascript

本文关键字:存在 批处理文件 服务器 javascript 运行 Apache 使用      更新时间:2023-09-26

我们尝试使用 java 脚本运行 apache 服务器中存在的 bat 文件。 我们收到以下错误"自动化服务器无法创建对象" 请找到以下代码,让我们知道如何解决问题

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script>    
    function testing() {
        alert("Execution will start");
        WshShell = new ActiveXObject("WScript.Shell");
        alert("after webShell");
        //var commandtoRun = "C:''Program Files''Apache Group''Apache2''htdocs''application''gui''templates''execute''test.bat";
        WshShell.Run ("'"C:''Program Files''Apache Group''Apache2''htdocs''application''gui''templates''execute''test.bat'"");
        alert("after webShell");
    }
    </script>
</head>

    enter code here
    <body> 
    <form>
    <p id="demo">Running scripts </p>
    <input type="button" onclick="javascript: testing ();" value="Run Scripts" />
    <button onclick="javascript: testing ();">Run bat File</button>
    </form>
    </body>
    </html>

JavaScript 在客户端执行。 您提供的位置将引用客户端计算机。 要么将文件放在客户端给定位置,要么编写服务器端代码。 如下。 我希望您使用的是 JSP。

例如

    <% String script="Write your script"%>
    <script> 
function testing(var script) {        
        WshShell = new ActiveXObject("WScript.Shell");              
        WshShell.Run (script);       
    }
var script1=<%=script%>
testing(script1);
    </script>