Environment Variables in WSH JS

  • Thread starter Dr John Stockton
  • Start date
D

Dr John Stockton

In javascript executed by Windows Scripting Host, one can input via
command-line parameters : File $95.js :-
x = WScript.Arguments
WScript.echo("Result:", x.length, typeof x, x[1], "OK")

Prompt>cscript //nologo $95.js 66 77 88
Result: 3 object 77 OK
The Arguments are 0-based.

Can one read/write Environment variables, and if so how? An answer for
VBscript could be useful, as well or in lieu.


Aside : <FAQENTRY> 2.11 : "over 5 years" is IMHO ambiguous. Suggest
"more than 5 years" or "for 5 years", whichever is meant.
 
Y

Yann-Erwan Perio

Dr said:
Can one read/write Environment variables, and if so how? An answer for
VBscript could be useful, as well or in lieu.

Use the WshShell object to read the Environment property:

---
var ws, en, buf;

ws=WScript.CreateObject("WScript.Shell");
en=new Enumerator(ws.Environment)
buf=[];

for(;!en.atEnd();en.moveNext())
buf.push(en.item());

WScript.Echo(buf.join("\n"));
ws=null;
---

Reference:<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsProEnvironment.asp>
Download:<URL:http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp>


HTH
Yep.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top