0

So I'm trying to execute a .bat file from a JS code:

My HTML code includes:

<body dir=rtl onload="runExe()">

as my main.js JavaScript code is:

function runExe(){
    var shell = new ActiveXObject("WScript.Shell");
    var path = 'write.bat';
    shell.run(path,1,false);
}

The write.bat file adds a "success" word to a .txt file. So far this code has no output to the text file. with a simple alert('x') command I realized that the code stops at the second line of JS code. Any ideas why? Is there something wrong with the ActiveXObject code?

Mitch Tal
  • 41
  • 7
  • Do you get any errors? Does write.bat work if you run it by itself? BTW you realise ActiveX is dead technology? I'd highly recommend not writing any new code which uses it, if you can possibly avoid it. – ADyson Mar 29 '19 at 11:44
  • 1
    "Is there something wrong with the ActiveXObject code?" — It's unsupported in most browsers. Only IE ever supported it. I don't know if IE11 supports it. – Quentin Mar 29 '19 at 11:47
  • 1
    I think the only mistake in your code is that `path` is not absolute and cmd can't find `write.bat`. Changed it to an absolute path like `D:\\write.bat` (remember to escape the \ character), and it worked for me in IE. – Dhruv Murarka Mar 29 '19 at 11:55
  • Thank you, all of you. I think that "technology" is indeed dead. I'm testing it on Chrome so that might be the reason. Any suggestions on how to code something like that? – Mitch Tal Mar 29 '19 at 21:13

0 Answers0