-1

My prog.js looks like this:

var WshShell = WSH.CreateObject("WScript.Shell");
var env = WshShell.Environment("PROCESS");
WSH.Echo(env.Length);  // 46
WSH.Echo(env("OS")); // Windows_NT
WSH.Echo(env.Item("OS")); // Windows_NT

Output:

> cscript /nologo prog.js
46
Windows_NT
Windows_NT

How do I print all 46 environment variables? I've tried env.Item(0), env.Item(1), but they are empty strings.

0

1 Answer 1

0

I've found it on https://www.cs.odu.edu/~wild/windowsNT/Spring00/wsh.htm :

var WshShell = WSH.CreateObject("WScript.Shell");
var env = WshShell.Environment("PROCESS");
var enum = new Enumerator(env);
while (!enum.atEnd()) {
  WSH.Echo(enumProcess.item());
  enumProcess.moveNext();
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.