开发者

How to enumerate my environmental variables in JScript?

开发者 https://www.devze.com 2023-03-31 21:22 出处:网络
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(\"

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

精彩评论

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