开发者

How to enumerate my environmental variables in JScript?

How do I enumerate my process's environ开发者_运维技巧mental variables in JScript, and, say, output them to the screen?


The solution is the same as in this answer, only you use WshShell.Environment("Process") instead of 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());
}


A quick google gives the following example:

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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜