0

i m trying to call a .bat file through my java script code...the bat file in turns calls a java file..but i m facing an error with the calling of .bat file plz help....also it gives mi error with the java class.... is this code rite??

    <html> 
       <head> 
                 <script language="JavaScript" type="text/javascript">  
                 MyObject = new ActiveXObject( "WScript.Shell" )  
                 function Runbat()   
                 {  
                  MyObject.Run("C:\\Documents and        Settings\\shraddha\\Desktop\\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> 
2
  • First, why the extra space in Documents and Settings? Second, you may need to insert extra " quotes within the string, around the path+filename. Commented Mar 19, 2013 at 18:36
  • 1
    Worked for me after I corrected the path and told IE to "allow blocked content". Commented Mar 19, 2013 at 18:48

1 Answer 1

2

Here is your code formatted properly. Note that your HTML is missing the closing </p> tag and DOCTYPE.

<html>
    <head>
        <script language="JavaScript" type="text/javascript">
            MyObject = new ActiveXObject("WScript.Shell")
            function Runbat()
            {
                MyObject.Run("\"C:\\Documents and Settings\\shraddha\\Desktop\\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>

See http://validator.w3.org/ for your HTML issues.

Sign up to request clarification or add additional context in comments.

2 Comments

Dear @David Ruhmann , ActiveXObject is available only on IE browser. What is your solution for chrome?
Chrome does not have an out of the box solution to executing files on a system due to its sandbox. Doing so, even in IE, is not recommended due to security concerns. There are probably some 3rd party solutions (such as chrome extensions) that can allow this, but off the top of my head there are no native Chrome solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.