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> 
colliyojiya
  • 1
  • 1
  • 1
  • 1
  • First, why the extra space in `Documents and Settings`? Second, you may need to insert extra " quotes within the string, around the path+filename. – AjV Jsy Mar 19 '13 at 18:36
  • 1
    Worked for me after I corrected the path and told IE to "allow blocked content". – rojo Mar 19 '13 at 18:48

1 Answers1

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.

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
  • Dear @David Ruhmann , `ActiveXObject` is available only on IE browser. What is your solution for chrome? – Hosein Aqajani Dec 09 '15 at 07:02
  • 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. – David Ruhmann Dec 09 '15 at 18:15