Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
Windows Script Host
 ExpandEnvironmentStrings Method
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Windows Script Host
ExpandEnvironmentStrings Method

Returns an environment variable's expanded value.

object.ExpandEnvironmentStrings(strString) 
object

WshShell object.

strString

String value indicating the name of the environment variable you want to expand.

The ExpandEnvironmentStrings method expands environment variables defined in the PROCESS environment space only. Environment variable names, which must be enclosed between "%" characters, are not case-sensitive.

The following code expands the Windows Directory environment variable and displays it:

VBScript
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "WinDir is " & WshShell.ExpandEnvironmentStrings("%WinDir%")
JScript
var WshShell = WScript.CreateObject("WScript.Shell");
WScript.Echo("WinDir is " + WshShell.ExpandEnvironmentStrings("%WinDir%"));

Applies To:

Reference

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
It may seem obvious but...      John Sudds   |   Edit   |   Show History

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%

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker