Share via


System.Environment.getEnvironmentVariable method

[The Windows Gadget Platform/Sidebar is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. ]

Retrieves the value of a system or user environment variable.

Syntax

strRetVal = System.Environment.getEnvironmentVariable(
  strEnvVar
)

Parameters

strEnvVar [in]

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

Examples

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;
    }
}

Requirements

Minimum supported client
Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2008 [desktop apps only]
End of client support
Windows 7
End of server support
Windows Server 2008
IDL
Sidebar.idl
DLL
Sidebar.Exe (version 1.00 or later)

See also

Reference

System.Environment

machineName