0

Is it possible to execute commands such as /ipconfig by double-clicking a JavaScript file on your desktop? Just like you do with VBScripts in Windows.

If not, is there any Java-based scripting file type that can handle this?

With scripting file type I mean something such as .BAT, .VBS or .PS1. Avoid .JAVA or .JAR answers as these files aren't as easy to build nor they are scripts.

  • you can right code in node.js and bundle node.js with electron to build portable executable – Jain Dec 12 '18 at 13:09
  • You're probably looking for JScript (not JavaScript), see [here](https://stackoverflow.com/questions/1441867/is-there-a-way-to-run-a-command-line-command-from-jscript-not-javascript-in-wi). – yeputons Dec 12 '18 at 13:10

3 Answers3

1

you cannot directly execute a javascript file. You have to use Nodejs from a command line or somehow call nodejs to execute a particular .js file from a .bat, .exe etc file

Doğancan Arabacı
  • 3,934
  • 2
  • 17
  • 25
0

With a batch(.bat) file:

@Echo off
pause
cd\windows\system32
ipconfig /all
pause
exit
n1kkou
  • 3,096
  • 2
  • 21
  • 32
0

Make 2 files:

File 1 - script.js:

'use strict';
console.log("Hello from script!");

File 2 - test.js

'use strict';
const cp = require('node:child_process');
const command = "node script.js"
cp.execSync(command, { stdio: 'inherit' });

Run:

node test.js

Expected output:

"Hello from script!"

Vinny
  • 21
  • 3