ExpandEnvironmentStrings Method
Returns an environment variable's expanded value.
object.ExpandEnvironmentStrings(strString)
The following code expands the Windows Directory environment variable and displays it:
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "WinDir is " & WshShell.ExpandEnvironmentStrings("%WinDir%")
var WshShell = WScript.CreateObject("WScript.Shell"); WScript.Echo("WinDir is " + WshShell.ExpandEnvironmentStrings("%WinDir%"));
Applies To:
It may seem obvious but...
If the environment variable is not defined, the method cannot "expand" the value and returns a string equal to the input.
var oShell = new ActiveXObject("WScript.Shell");
var strReturn = oShell.ExpandEnvironmentStrings("%MISSING%");
WScript.Echo(strReturn);
Example output: %MISSING%
- 6/18/2008
- John Sudds [Microsoft]