The ExpandEnvironmentStrings method expands the environment variables in a string and returns the resulting string.
Environment variables are case-insensitive and are enclosed by a pair of % characters. If an environment variable in strString is undefined, then it is left unchanged.
Set WshShell =
CreateObject("WScript.Shell")
strOriginalString =
"Windows is installed in %WinDir%. %XYZ% is undefined."
strExpandedString =
WshShell.ExpandEnvironmentStrings(strOriginalString)
WScript.Echo "Before: " & strOriginalString
WScript.Echo "After: " & strExpandedStringBefore: Windows is
installed in %WinDir%. %XYZ% is undefined.
After: Windows is
installed in C:\WINNT. %XYZ% is undefined.This VBScript code illustrates the behavior of this method.