8.2.4 GetEnvironment or GetEnv (get an environment variable)
- Purpose
-
Gets an environment variable.
- Syntax
GetEnvironment (Type, EnvironmentName [, Option]) GetEnv (Type, EnvironmentName [, Option])
- Arguments
-
- Type
-
Specify whether the environment variable you are defining is a system environment variable, user environment variable, or an environment variable for the current process.
Use one of the following values:
Value
Meaning
SystemEnv
System environment variable
UserEnv
User environment variable
ProcessEnv
Environment variable for the current process
- EnvironmentName
-
Write the name of the environment variable as a character string or as a variable that stores this value.
- Option (from version 05-20)
-
Specify the following option:
Value
Meaning
Expand
If the value to be obtained includes a reference to an unexpanded environment variable ("%PATH%", for example), get the expanded value.
- Description
-
The GetEnvironment command gets a specified environment variable and returns its value as the execution result.
If you specify a non-existent environment variable, a zero-length string ("") is returned.
- Note
-
If the value of the specified environment variable is a character string containing 1,025 or more bytes, the command returns the first 1,024 bytes as the execution result. The 1,025th and subsequent bytes are ignored.
- Examples
' If environment variable path has the value "C:\Winnt", ' this code stores "C:\Winnt" in variables buff1 and ' buff2. Dim buff1, buff2 buff1 = GetEnvironment (SystemEnv, "path") buff2 = GetEnvironment (SystemEnv, "path", Expand) ' If environment variable path has the value ' "%SystemRoot%" and environment variable SystemRoot has ' the value "C:\Winnt", this code stores "%SystemRoot%" ' in variable buff3, and "C:\Winnt" in variable buff4. Dim buff3, buff4 buff3 = GetEnvironment (SystemEnv, "path") buff4 = GetEnvironment (SystemEnv, "path", Expand)
- JP1/Script version
-
Supported from JP1/Script 01-00.