Using RVL
Define the following functions in your User.js file:
/**
* Read environment variable `name`.
*
*/
function GetEnvVar(/**string*/name)
{
if(name.indexOf("%")==-1)
{
name = "%"+name+"%";
}
var val = g_helper.ResolveEnvironmentVariables(name)
return val;
}
/**
* Expand string referring to environment variables (i.e. %ROOT%\File.txt)
*/
function ExpandEnvVar(/**string*/name)
{
var val = g_helper.ResolveEnvironmentVariables(name)
return val;
}
Use them in RVL:
Or in JavaScript:
function Test(params)
{
Tester.Message("path" + GetEnvVar("path"));
Tester.Message("PATH" + GetEnvVar("PATH"));
Tester.Message("Expanded path: "+ExpandEnvVar("%WORKDIR%\\File.txt"));
}
Using built-in g_helper object
var helloUser = g_helper.ResolveEnvironmentVariables("Hello, %UserName%")
Using Process Environment
var WshShell = new ActiveXObject("WScript.Shell");
var _processEnv = WshShell.Environment("PROCESS");
var userName = _processEnv("UserName");
Expanding the String
var WshShell = new ActiveXObject("WScript.Shell");
var helloUser = WshShell.ExpandEnvironmentStrings("Hello, %UserName%")