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
1 Answer
Reset to default 1WScript
is an object provided by the W|CScript.exe hosts; IExplorer or MSHTA don't provide it (see here).Console
is an object provided by (some) browsers. A script runninng under C|WScript.exe can useWScript.Echo
instead.- You need to open and type-specify a stream before you can write to it.
- 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
评论列表(0条)