0

I am running a JS script on a machine and I want it to open a file that is on that machine. It's supposed to be a minecraft server bot that will open batch files that opens a specific server client, which are needed to start the server with the correct amount of allocated ram. So examples of why I would need it would be that I have modded and vanilla server clients. Say it were to receive "!start vanilla" or something along those lines, it then runs the batch file to start the server. I've been trying to use the wshShell method, but I always get "TypeError: wshShell.Run is not a function"

var wshShell = new ActiveXObject('WScript.Shell');
wshShell.Run("C:\\users\\user\\desktop\\test.bat");

I'm also not sure as to why ActiveXObject errors out. I'm still relatively new to JS so I've been kind of looking online for help. Hopefully I provided enough information to get some help on this.

  • ActiveX _was_ a tool mainly used in local network environments for a couple of decades ago, in Internet Explorer only. There's no way to execute system commands on a web page in modern browsers. (IE can still do this, if it's allowed in Internet settings, but I doubt anybody has ActiveX execution allowed on Internet zone.) – Teemu Aug 22 '20 at 06:56
  • Would tell, it is still possible in IE only or in HTA (common page with this extension). But there is need to confirm ActiveX. Not sure about server, but definitely works from local page (.hta like a charm and after confirm in html too). I have even a fake ActiveX script for node.js to be able to work with easily (HTA has old browser by default and limited developer tools - full Visual Studio only, it is slow,...). There is tag to emulate newer browser in hta and it is handy for small local cmd tools, but a bit of security hole and another alternative should be C# of .Net, but w/o GUI. – Jan Aug 22 '20 at 07:04
  • In case you want some inspiration, here are some published files https://github.com/eltomjan/ETEhomeTools/tree/master/HTM_HTA in KDD.HTA that tag for example (by default 6?) and fakeAX.js used to fine tune HTA scripts in Visual Studio Code with node.js – Jan Aug 22 '20 at 07:18

1 Answers1

0

Refer to this answer here How to run .exe file or .bat file based on button click event using Javascript


You can try something like that with a HTA file : Just save this code as Run_MiniCraft.hta and not Run_MiniCraft.html and executes it by double click on it !


<html>
<head>
<title>Run Exe or Bat files from HTA</title>
</head>
<script>
function RunME(){
    var shell = new ActiveXObject("WScript.Shell");
    var path = '%userprofile%\\desktop\\Test.bat';
    shell.run(path,1,false);
}
</script>
<input style="width: 170px; height:23px; color: white; background-color: #603040; 
font-family:Book Antiqua;" type="button" Value="Run MiniCraft Server" onClick="RunME();"
</html>
Hackoo
  • 18,337
  • 3
  • 40
  • 70