javascript - ReferenceError: WScript is not defined - Stack Overflow

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

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", ".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?

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./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?

Share Improve this question edited Aug 10, 2016 at 20:59 user692942 16.4k8 gold badges84 silver badges190 bronze badges asked Aug 10, 2016 at 17:48 Julie19872Julie19872 511 gold badge1 silver badge2 bronze badges 2
  • What environment are you trying to do this in? Looks like old Windows Script Host stuff. If you're trying to do it in a browser, it's not going to work. The XHR stuff you can do with XMLHttpRequest. You can't save a file to the user's filesystem though. – T.J. Crowder Commented Aug 10, 2016 at 17:52
  • I just tried running the js file instead of opening it through a browser. I get no error once I remove the console.log(er); line since it was planing about that. For some reason it's not writing anything to C:\ like that. Any idea why, or how I would debug it (ie. see what's being returned from xo, if anything)? – Julie19872 Commented Aug 10, 2016 at 18:06
Add a ment  | 

1 Answer 1

Reset to default 1
  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./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);

};

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264551a4619374.html

相关推荐

  • javascript - ReferenceError: WScript is not defined - Stack Overflow

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

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信