Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


8.2.3 SetEnvironment or SetEnv (set an environment variable)

Purpose

Sets an environment variable.

Syntax
SetEnvironment (Type, EnvironmentName [, Value])
SetEnv (Type, EnvironmentName [, Value])
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

Takes effect at system restart after execution of this command.

Can be obtained after command execution using the GetEnvironment command.

UserEnv

User environment variable

Takes effect at system restart after execution of this command.

Can be obtained after command execution using the GetEnvironment command.

ProcessEnv

Environment variable for the current process

Takes effect only within the current process after execution of this command.

If you specify SystemEnv, execute the script file as a user who has administrator permissions. For details, see 1.8.2 Command behavior.

EnvironmentName

Write the name of the environment variable as a character string or as a variable that stores this value.

Value

Write the value of the environment variable as a character string or as a variable that stores this value.

This value is optional. If you omit this value, a zero-length string ("") is assumed.

If the value you specify contains a reference to the unexpanded environment variable ("%PATH%", for example), the value is still set as specified. For example, if you set "%PATH%;C:\Data" in Value, "%PATH%;C:\Data" is set as the value of the environment variable. However, when this environment variable is referenced, the system obtains a value in which the %PATH% portion is replaced by the current value of the PATH environment variable. To specify a process environment variable, which cannot be replaced with the current value, code the script as shown in Example 1. If the system cannot find a PATH environment variable, it gets the "%PATH%" portion as is.

Description

The SetEnvironment or SetEnv command sets a specified value in a specified environment variable. The command returns True on successful execution, or False if an error occurs.

If you specify a non-existent environment variable, a new environment variable is created with the specified value. If you specify an existing environment variable, its value is updated.

Example 1
' Add "C:\ABC\" to the PATH process environment variable.
Dim buff1
buff1 = GetEnvironment ( ProcessEnv ,"PATH" )
SetEnvironment ( ProcessEnv ,"PATH" ,buff1 & ";C:\ABC\" )
Exec ( "ABC.EXE" ,True )
Example 2
' Set the PATH environment variable to the APP_PATH system 
' environment variable.
SetEnvironment ( SystemEnv ,"APP_PATH" ,"%PATH%" )
JP1/Script version

Supported from JP1/Script 01-00.