Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 485 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run a bat file from javascript

#1
I'm trying to run a bat file using javascript. I've tried using powershell but it didn't seem to work properly. Here is the code I tried:

var oShell = WScript.CreateObject("WScript.Shell");
oShell.Exec("D:");
oShell.Exec("cd dir");
oShell.Exec("start user.bat");

I've also tried that:

var oShell = WScript.CreateObject("WScript.Shell");
oShell.Exec("start D:\dir\user.bat");

Sometimes it runs, sometimes I get those errors "Expected hexadecimal digit", "Access is denied".
I'm really confused. All I'm trying to do is execute a bat file from a javascript file.

Anyone has any idea how to do it? Thank you!
Reply

#2
First, JavaScript doesn't have any operating system services. So you are really referring to a Windows Script Host (WSH) script that happens to be written in JavaScript.

Second, `start` is not an executable but rather a command that is built into `cmd.exe`.

With the confusion out of the way, it sounds like you want to execute a shell script (batch file) from a WSH script. The simplest way is like this (this is somewhat close to what you tried already):

var wshShell = new ActiveXObject("WScript.Shell");
wshShell.Run("D:\\dir\\user.bat");

To create the `WshShell` COM object reference (progid `WScript.Shell`), use the `new` keyword and the `ActiveXObject` constructor. Also, you need to double your backslashes (`\`) in JavaScript strings because `\` escapes characters in JavaScript strings.
Reply

#3
Also, check the following version it might help;

var runnableScript = exec('path_to.bat',
(error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through