Using WScript.Shell to get environment variables

The docs say that XSIUtils.Environment gets system environment variables, but I think it is more accurate to say that it returns env vars of the XSI.exe process.

WScript.Shell is another way to get at the environment variables. The WshShell object’s Environment property is a collection of environment variables. For example, this snippet shows how to create a WScript.Shell object, and then check the value of the TEMP environment variable. Note that XSI.exe creates its own folder under the location pointed to by the User TEMP environment variable.

// Get WshShell object.
var oWshShell = new ActiveXObject ("WScript.Shell");

var oEnv = oWshShell.Environment("Process");
LogMessage( oEnv("TEMP") );

// INFO : C:\Users\blairs\AppData\Local\Temp\XSI_Temp_17480

var oEnv = oWshShell.Environment("User");
LogMessage( oEnv("TEMP") );
LogMessage( oWshShell.ExpandEnvironmentStrings("%USERPROFILE%") );

// INFO : %USERPROFILE%\AppData\Local\Temp
// INFO : C:\Users\blairs

You can also loop over the collection:

var oEnv = oWshShell.Environment("System");
logenv( oEnv );

function logenv( o )
	oEnum = new Enumerator( o ) ;
	for (;!oEnum.atEnd();oEnum.moveNext() )
		var oSelItem = oEnum.item() ;
		LogMessage( oSelItem  );