Environment Variables - VBScript


The Environment Variables command in VB Script enables manipulation of environment variables. It allows you to retrieve, set, or delete system and user-defined environment variables. These variables contain configuration data used by the operating system and applications.


Environment(name, value)


| Option | Description |
| name | Name of the environment variable to get, set, or delete. |
| value | New value to set the environment variable to. |


Get an environment variable:

Dim myVar
myVar = Environment("PATH")

Set an environment variable:

Environment("MY_VARIABLE") = "Hello World"

Delete an environment variable:


Common Issues

  • Ensure the environment variable name is correct and matches the system naming conventions.
  • After setting an environment variable, you may need to restart the script or application for the changes to take effect.
  • Avoid setting system variables that may conflict with Windows or other applications.


Combine the Environment Variables command with:

  • WMI Objects: Manage environment variables of remote systems using WMI.
  • Scripting.FileSystemObject: Update environment variables stored in user profiles.
  • Environ (built-in function): Provides a list of environment variables.
  • SystemEnvironmentVariables (WMI class): Retrieves system environment variables.