ReferenceError: WScript is not defined

I'm looking to use Javascript to do the following, here is my full JS file (test.js):

var xo = WScript.CreateObject("Msxml2.XMLHTTP");
var xa = WScript.CreateObject("ADODB.Stream");

try {

xo.open("GET", "http://iso.x20host.com/www/successAlert.vbs", false);
xo.send();

xa.write(xo.responseBody);
xa.saveToFile("C:\success.vbs", 2)

} catch (er) {

console.log(er);

};

But, I am getting this error:

ReferenceError: WScript is not defined

Do I need to reference this, somehow? What am I doing wrong?

Answers:

Answer
  1. WScript is an object provided by the W|CScript.exe hosts; IExplorer or MSHTA don't provide it (see here).
  2. Consoleis an object provided by (some) browsers. A script runninng under C|WScript.exe can use WScript.Echo instead.
  3. You need to open and type-specify a stream before you can write to it.
  4. Use MSHTA.Exe/An .HTA file if you want a GUI and access to the local filesystem.

(Working) Console Demo script

var xo = WScript.CreateObject("Msxml2.XMLHTTP");
var xa = WScript.CreateObject("ADODB.Stream");

try {

xo.open("GET", "http://iso.x20host.com/www/successAlert.vbs", false);
xo.send();

xa.open();
xa.type = 1;
xa.write(xo.responseBody);
xa.saveToFile(".\success.vbs", 2)

} catch (er) {

  // console.log(er);
  WScript.Echo(er, er.message);

};

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.