WSH » wshshell » ExpandEnvironmentStrings

Syntax:
WshShell.ExpandEnvironmentStrings (strString)
strString
Receives a string containing one or more environment variables.

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.

Examples

Code:
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: " & strExpandedString
Output:
Before: Windows is installed in %WinDir%. %XYZ% is undefined.
After: Windows is installed in C:\WINNT. %XYZ% is undefined.
Explanation:

This VBScript code illustrates the behavior of this method.

Language(s): VBScript