Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Gadgets
Windows Sidebar
System.Environment
Methods
 getEnvironmentVariable Method
getEnvironmentVariable Method

Retrieves the value of a system or user environment variable.

Syntax

strValue = System.Environment.getEnvironmentVariable(strEnvVar)

Parameters

strEnvVar Required. String that specifies the name of an environment variable.

Return Value

The value of the specified environment variable.

Remarks

System environment variables define the behavior of the global operating system environment. Local environment variables define the behavior of the environment of the current user session.

The following is a selection of valid environment variables:

  • ALLUSERSPROFILE=C:\ProgramData
  • APPDATA=C:\Users\user\AppData\Roaming
  • HOMEPATH=\Users\user
  • LOCALAPPDATA=C:\Users\user\AppData\Local
  • PROGRAMDATA=C:\ProgramData
  • PUBLIC=C:\Users\Public
  • TEMP=C:\Users\user\AppData\Local\Temp
  • TMP=C:\Users\user\AppData\Local\Temp
  • USERPROFILE=C:\Users\user

Example

The following example demonstrates how to retrieve the value of an environment variable.

// --------------------------------------------------------------------
// Set the text of the gadget based on the environment variable.
// --------------------------------------------------------------------
function SetContentText()
{
    var environmentVariableValue = 
        System.Environment.getEnvironmentVariable(environmentVariableName);
    
    if (environmentVariableValue)
    {
        gadgetContent.innerHTML = environmentVariableName + 
            ": " + environmentVariableValue;
    }
    else
    {
        gadgetContent.innerHTML = defaultText;
    }
}

Applies To

System.Environment

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker