3

I'm attempting to create a button that opens and executes a batch file so that it easier for everyone to access.

<input type="button" value="Test" onclick="window.open('bat:///\\123.hello.net\FileShares\ Logon\SAPfileConfig.bat')" />

Whenever I execute on IE, it says that file cannot be found.

What could I be doing wrong?

Compo
  • 36,585
  • 5
  • 27
  • 39
Kim
  • 31
  • 1
  • 1
  • 4
  • What is the location of your batch file ? – Hackoo Mar 23 '18 at 19:00
  • Take a look at this [How to run .exe file or .bat file based on button click event using Javascript](https://stackoverflow.com/questions/36104713/how-to-run-exe-file-or-bat-file-based-on-button-click-event-using-javascript?answertab=active#tab-top) – Hackoo Mar 23 '18 at 19:08
  • Hi Hackoo, it's on a folder on a shared drive! – Kim Mar 23 '18 at 19:09
  • What's the UNC Path ? i don't think is like this : `bat:///` ? – Hackoo Mar 23 '18 at 19:16
  • I apologize that was a mistake I meant it to be file: but the UNC path is \\123.hello.net\FileShares\Logon\Config.bat – Kim Mar 23 '18 at 19:32

2 Answers2

4

You will not be able to execute a bat file using your web page. You may able to make it download automatically, but it will not be executed automatically for some security issue

NIKHIL NEDIYODATH
  • 2,703
  • 5
  • 24
  • 30
  • Hi Nikhil! This isn't from a web page, it's from a file from our shared drive in which I have renamed for security purposes. – Kim Mar 23 '18 at 19:08
  • 1
    In this case, it is similar to loading from a website, you will not be able to execute it. If my answer is useful for you please accept and upvote my answer. Thank you – NIKHIL NEDIYODATH Mar 23 '18 at 19:12
2

You can try with a HTA file like this : Run Exe or Batch files with Javascript and HTA

Javascript_Execute.hta

<html>
<head>
<title>Run Exe or Batch files with Javascript and HTA</title>
<HTA:APPLICATION
  APPLICATIONNAME="Run Exe or Batch files with Javascript and HTA"
  ID="MyHTMLapplication"
  VERSION="1.0"/>
</head>
<script language="Javascript">
function RunMe(){
    var shell = new ActiveXObject("WScript.Shell");
    var path = '"file:\\\\123.hello.net\\FileShares\\Logon\\SAPfileConfig.bat"';
    shell.run(path,1,false);
}
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040; 
font-family:Book Antiqua;" type="button" Value="Execute Batch File" onClick="RunMe();"
</html>

Or you can Run Exe or Batch files with Vbscript and HTA :

Vbscript_Execute.hta

<html>
<head>
<title>Run Exe or Batch files with Vbscript and HTA</title>
<HTA:APPLICATION
  APPLICATIONNAME="Run Exe or Batch files with Vbscript and HTA"
  ID="MyHTMLapplication"
  VERSION="1.0"/>
</head>
<script language="Vbscript">
Function RunMe()
Dim Shell,path
Set shell = CreateObject("WScript.Shell")
path = "file:\\123.hello.net\FileShares\Logon\SAPfileConfig.bat"
shell.run path,1,false
End Function
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040; 
font-family:Book Antiqua;" type="button" Value="Execute Batch File" onClick="RunMe()"
</html>
Hackoo
  • 18,337
  • 3
  • 40
  • 70