如何在 JScript 中枚举我的进程的环境变量,然后将它们输出到屏幕上?
问问题
4092 次
2 回答
8
解决方案与此答案中的相同,只是您使用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());
}
于 2011-08-31T19:59:59.373 回答
1
一个快速的谷歌给出了以下示例:
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")
于 2011-08-31T17:29:15.670 回答