2013-10-01 120 views
1

我們正在嘗試使用java腳本運行Apache服務器中存在的bat文件。 我們正在以下錯誤「自動化服務器無法創建對象」 請找到下面的代碼,讓我們知道如何解決這個問題使用javascript運行Apache服務器中的批處理文件

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

您確定要將其作爲ActiveX而不是CGI嗎? – Amadan

回答

0

的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> 
相關問題