如何在JScript中枚举我的环境变量?

时间:2011-08-31 17:24:09

标签: javascript environment-variables wsh jscript

如何在JScript中枚举我的进程的环境变量,并将它们输出到屏幕?

2 个答案:

答案 0 :(得分:8)

解决方案与this answer相同,只有您使用WshShell.Environment("Process")代替WshShell.Environment("User")

var oShell = new ActiveXObject("WScript.Shell");
var oUserEnv = oShell.Environment("Process");

var colVars = new Enumerator(oUserEnv);
for(; ! colVars.atEnd(); colVars.moveNext())
{
  WScript.Echo(colVars.item());
}

答案 1 :(得分:1)

快速google给出了以下示例:

Set objShell = WScript.CreateObject("WScript.Shell")
Set colSystemEnvVars = objShell.Environment("System")
Set colUserEnvVars = objShell.Environment("User")
Wscript.Echo "Computer-specific PATH Environment Variable"
Wscript.Echo colSystemEnvVars("PATH")
Wscript.Echo "User-specific PATH Environment Variable"
Wscript.Echo colUserEnvVars("PATH")