# Set Environment Variable

> `UiPath.Core.Activities.SetEnvironmentVariable`

`UiPath.Core.Activities.SetEnvironmentVariable`

Use this activity to set an environment variable, providing the name and the value for it. If the variable does not already exist, it will be created automatically.

:::note
On Windows, this activity sets **User Environment Variables**. On cross-platform projects, it sets **Process Environment Variables**.
Understanding how environment variables are loaded from Machine and User levels into the Process scope is important for interpreting the Windows and cross-platform behavior differences of the **Get Environment Variable** and **Set Environment Variable** activities.
:::

## Properties

#### **Common**

* **DisplayName** - The display name of the activity. This field supports only `Strings` or `String` variables.

#### **Input**

* **Name** - The name of the new environment variable. This field supports only `Strings` or `String` variables.
* **Value** - The value of the new environment variable. This field supports only `Strings` or `String` variables.

#### **Misc**

* **Private** - If selected, the values of variables and arguments are no longer logged at Verbose level.

## Platform-specific behavior

### Windows environment

When running on Windows (default configuration):

* Environment variables are set at the User level (`EnvironmentVariableTarget.User`).
* Changes persist beyond the current process and are stored in the Windows registry.
* The variable becomes available to new processes started by the current user.
* Requires appropriate permissions to modify user-level environment variables.

### Cross-platform environment

When running on cross-platform systems (Linux, macOS):

* Environment variables are set at the Process level (`EnvironmentVariableTarget.Process`).
* Changes are temporary and only affect the current process and its child processes.
* Variables are not persisted after the process terminates.
* No special permissions are required because changes are scoped to the current process.

## Technical details

The activity uses an internal `TargetFramework` property to determine the execution context. This behavior is determined automatically by the UiPath runtime based on the project type and cannot be configured through the activity properties.

## Best practices

* For Windows workflows, use this activity when variables must persist across process restarts or be available to other applications.
* For cross-platform workflows, plan for process-level scope and use alternative persistence (configuration files, databases) when needed.
* For portable workflows, design assuming process-level scope to ensure consistent behavior across platforms.

## Validation

The activity validates that the **Name** parameter is not null or empty and that all required arguments are provided. Invalid operations throw an `InvalidOperationException` with a descriptive error message.
