The environment object can be used to manipulate environment variables.
Properties | Description |
EnvironmentVar | Name of the variable |
EnvironmentVal | Value for the variable |
EnvironmentType | Variable type (0=System, 1=User) |
Propagate
|
Should the variable be propagated (True or False)
|
Methods | Description |
GetEnvironmentVar
|
Retrieve the value of the environment variable Optionally accepts a variable to receive the returncode Returns a Boolean value (True if successful)
Function GetEnvironmentVar(lngReturnValue As Long) |
SetEnvironmentVar
|
Create, modify or delete the environment variable Optionally accepts a variable to receive the returncode Returns a Boolean value (True if successful)
Function SetEnvironmentVar(lngReturnValue As Long) |
ActivateEnvironmentVar
|
Propagate the (pending) variables to the system Returns a Boolean value (True if successful)
Function ActivateEnvironmentVar(lngReturnValue As Long) |
To delete an environment variable, simply set it to an empty value.
Usage:
Sub Scense_Main() With Environment .EnvironmentType = 1 'User .EnvironmentVar = "TestVar" .EnvironmentVal = "aaaa" 'Set the Variable for the current process If .SetEnvironmentVar(rc) Then WriteScenseLog "Unable to set the variable (Error: " & rc & ")" End If 'Propagate new environment value .ActivateEnvironmentVar End With End Sub