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.

2
  • you can right code in node.js and bundle node.js with electron to build portable executable Commented Dec 12, 2018 at 13:09
  • You're probably looking for JScript (not JavaScript), see here. Commented Dec 12, 2018 at 13:10

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

0

With a batch(.bat) file:

@Echo off
pause
cd\windows\system32
ipconfig /all
pause
exit

Comments

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!"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.