activities
latest
false
Wichtig :
Bitte beachten Sie, dass dieser Inhalt teilweise mithilfe von maschineller Übersetzung lokalisiert wurde. Es kann 1–2 Wochen dauern, bis die Lokalisierung neu veröffentlichter Inhalte verfügbar ist.
UiPath logo, featuring letters U and I in white

Workflow-Aktivitäten

Letzte Aktualisierung 6. März 2026

Umgebungsvariable erhalten (Get Environment Variable)

UiPath.Core.Activities.GetEnvironmentVariable

Use this activity to retrieve the value of an environment variable by providing its name. Understanding the platform-specific retrieval behavior is essential for building reliable cross-platform automation workflows.

Hinweis:

On Windows, this activity retrieves variables from User Environment Variables with fallback to Process Environment Variables. On cross-platform projects, it retrieves Process Environment Variables only. Understanding how environment variables are loaded from Machine and User levels into the Process scope is crucial for comprehending the Windows and cross-platform behavior differences of the Get Environment Variable and Set Environment Variable activities.

Eigenschaften

Allgemein
  • AnzeigeName (DisplayName) - Der Anzeigename der Aktivität. Dieses Feld unterstützt nur Strings oder String-Variablen.
Eingabe
  • Variable - The name of the environment variable whose value is to be retrieved. This field supports only Strings or String variables.
Ausgabe
  • VariablenWert (VariableValue) - Der Wert des ausgewählten Umgebungsvariable.
Sonstiges
  • Privat (Private) - Bei Auswahl werden die Werte von Variablen und Argumenten nicht mehr auf der Stufe Verbose protokolliert.

Platform-specific behavior

Windows environment

When running on Windows (default configuration):

  • The activity first attempts to retrieve the variable from the User level (EnvironmentVariableTarget.User).
  • If not found at the User level, it falls back to the Process level environment variables.
  • This fallback mechanism ensures that both user-specific and process-specific variables are accessible.
  • System properties exposed through System.Environment (e.g., MachineName, OSVersion, UserName) are always checked first regardless of scope.

Cross-platform environment

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

  • The activity retrieves variables only from the Process level (EnvironmentVariableTarget.Process).
  • This includes variables inherited from the parent process and any set during the current process execution.
  • No fallback mechanism is used since User-level variables are Windows-specific.
  • System properties exposed through System.Environment are still prioritized and accessible.

Retrieval priority

The activity follows this retrieval order:

1. System.Environment Properties (all platforms)

  • First checks if the requested variable name matches a built-in .NET property (e.g., CurrentDirectory, MachineName, ProcessorCount).
  • If matched, returns the property value directly.

2. Environment Variables

  • Windows: Checks User level first, then falls back to Process level.
  • Cross-Platform: Checks Process level only.

Technical details

The activity uses an internal TargetFramework property to determine the execution context:

  • "windows" - Uses EnvironmentVariableTarget.User with Process-level fallback.
  • "portable" - Uses EnvironmentVariableTarget.Process only.

This behavior is determined automatically by the UiPath runtime based on the execution environment and cannot be manually configured through the activity properties.

Behavioral differences

Variable persistence

  • Windows: Can retrieve persistent user-level variables set through Windows system settings or by the Set Environment Variable activity.
  • Cross-Platform: Only retrieves variables available in the current process scope (inherited from shell or set during execution).

Variablenumfang

  • Windows: Has access to a wider scope of variables (User + Process).
  • Cross-Platform: Has access to a narrower scope (Process only).

Best Practices

  • For Windows workflows, you can rely on user-level environment variables for configuration. The automatic fallback ensures process-level variables are still accessible.
  • For cross-platform workflows, only rely on environment variables passed to the process or set during execution. Do not depend on user-level variables as they won't be available. Consider passing required configuration through process arguments or configuration files.
  • For portable workflows, design workflows assuming Process-level scope only to ensure consistent behavior across platforms. Test that all required variables are available at process startup and document any environment prerequisites clearly.
  • System properties: Prefer using .NET's built-in System.Environment properties (like MachineName, UserName) when available, as they work consistently across platforms.

Rückgabewert

  • Returns the environment variable value as a string.
  • Returns empty string or null if the variable is not found (behavior may vary by platform and .NET version).
  • System property values are returned as strings using .ToString().

Beispielszenarien

Scenario 1: Reading PATH variable

  • Windows: Successfully retrieves from User or Process scope.
  • Linux/macOS: Successfully retrieves from Process scope.

Scenario 2: Reading a user-specific custom variable set via Windows System Properties

  • Windows: Successfully retrieves the value.
  • Linux/macOS: Returns empty/null (user-level variables don't exist).

Scenario 3: Reading MachineName

  • All Platforms: Successfully retrieves from System.Environment.MachineName property.

War diese Seite hilfreich?

Verbinden

Benötigen Sie Hilfe? Support

Möchten Sie lernen? UiPath Academy

Haben Sie Fragen? UiPath-Forum

Auf dem neuesten Stand bleiben