Environment.GetEnvironmentVariable Método

Definición

Recupera el valor de una variable de entorno.Retrieves the value of an environment variable.

Sobrecargas

GetEnvironmentVariable(String)

Recupera el valor de una variable de entorno del proceso actual.Retrieves the value of an environment variable from the current process.

GetEnvironmentVariable(String, EnvironmentVariableTarget)

Recupera el valor de una variable de entorno del proceso actual o de la clave del Registro del sistema operativo Windows para la máquina local o el usuario actual.Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.

GetEnvironmentVariable(String)

Recupera el valor de una variable de entorno del proceso actual.Retrieves the value of an environment variable from the current process.

public:
 static System::String ^ GetEnvironmentVariable(System::String ^ variable);
public static string GetEnvironmentVariable (string variable);
public static string? GetEnvironmentVariable (string variable);
static member GetEnvironmentVariable : string -> string
Public Shared Function GetEnvironmentVariable (variable As String) As String

Parámetros

variable
String

Nombre de la variable de entorno.The name of the environment variable.

Devoluciones

String

El valor de la variable de entorno especificada por variable o null si no se encuentra la variable de entorno.The value of the environment variable specified by variable, or null if the environment variable is not found.

Excepciones

variable es null.variable is null.

El autor de la llamada no tiene el permiso requerido para llevar a cabo esta operación.The caller does not have the required permission to perform this operation.

Ejemplos

En el ejemplo siguiente se usa el GetEnvironmentVariable método para recuperar la windir variable de entorno, que contiene la ruta de acceso del directorio de Windows.The following example uses the GetEnvironmentVariable method to retrieve the windir environment variable, which contains the path of the Windows directory.

using namespace System;
using namespace System::IO;

void main()
{
      if (Environment::OSVersion->Platform == PlatformID::Win32NT)
      {
            // Change the directory to %WINDIR%
            Environment::CurrentDirectory = Environment::GetEnvironmentVariable( "windir" );
            DirectoryInfo^ info = gcnew DirectoryInfo( "." );

            Console::WriteLine("Directory Info:   {0}", info->FullName);
      }
      else
      {
            Console::WriteLine("This example runs on Windows only.");
      }
}
// The example displays output like the following on a .NET implementation running on Windows:
//        Directory Info:   C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
//        This example runs on Windows only.
using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      if (Environment.OSVersion.Platform == PlatformID.Win32NT)
      {
         // Change the directory to %WINDIR%
         Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");
         DirectoryInfo info = new DirectoryInfo(".");

         Console.WriteLine("Directory Info:   " + info.FullName);
      }
      else
      {
         Console.WriteLine("This example runs on Windows only.");
      }
   }
}
// The example displays output like the following on a .NET implementation running on Windows:
//        Directory Info:   C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
//        This example runs on Windows only.
Imports System.IO

Module Example
   Public Sub Main()
        If Environment.OSVersion.Platform = PlatformID.Win32NT Then
            ' Change the directory to %WINDIR%
            Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
            Dim info As New DirectoryInfo(".")
            Console.WriteLine("Directory Info:   " + info.FullName)
         Else
            Console.WriteLine("This example runs on Windows only.")
         End If
   End Sub
End Module
' The example displays output like the following on a .NET implementation running on Windows:
'        Directory Info:   C:\windows
' The example displays the following output on a .NET implementation on Unix-based systems:
'        This example runs on Windows only.

En el ejemplo siguiente se intenta recuperar el valor de una variable de entorno denominada Test1 del bloque de entorno de proceso.The following example attempts to retrieve the value of an environment variable named Test1 from the process environment block. Si la variable no existe, el ejemplo crea y recupera su valor.If the variable doesn't exist, the example creates its and retrieves its value. En el ejemplo se muestra el valor de la variable.The example displays the value of the variable. Si en el ejemplo se crea la variable, también llama al GetEnvironmentVariables(EnvironmentVariableTarget) método con cada miembro de la EnvironmentVariableTarget enumeración para establecer que la variable solo se puede recuperar desde el bloque de entorno de proceso actual.If the example created the variable, it also calls the GetEnvironmentVariables(EnvironmentVariableTarget) method with each member of the EnvironmentVariableTarget enumeration to establish that the variable can be retrieved only from the current process environment block. Por último, si en el ejemplo se crea la variable, se elimina.Finally, if the example created the variable, it deletes it.

using System;

public class Example
{
   public static void Main()
   {
      string value;
      bool toDelete = false;

      // Check whether the environment variable exists.
      value = Environment.GetEnvironmentVariable("Test1");
      // If necessary, create it.
      if (value == null)
      {
         Environment.SetEnvironmentVariable("Test1", "Value1");
         toDelete = true;

         // Now retrieve it.
         value = Environment.GetEnvironmentVariable("Test1");
      }
      // Display the value.
      Console.WriteLine($"Test1: {value}\n");

      // Confirm that the value can only be retrieved from the process
      // environment block if running on a Windows system.
      if (Environment.OSVersion.Platform == PlatformID.Win32NT)
      {
         Console.WriteLine("Attempting to retrieve Test1 from:");
         foreach (EnvironmentVariableTarget enumValue in
                           Enum.GetValues(typeof(EnvironmentVariableTarget))) {
            value = Environment.GetEnvironmentVariable("Test1", enumValue);
            Console.WriteLine($"   {enumValue}: {(value != null ? "found" : "not found")}");
         }
         Console.WriteLine();
      }

      // If we've created it, now delete it.
      if (toDelete) {
         Environment.SetEnvironmentVariable("Test1", null);
         // Confirm the deletion.
         if (Environment.GetEnvironmentVariable("Test1") == null)
            Console.WriteLine("Test1 has been deleted.");
      }
   }
}
// The example displays the following output if run on a Windows system:
//      Test1: Value1
//
//      Attempting to retrieve Test1 from:
//         Process: found
//         User: not found
//         Machine: not found
//
//      Test1 has been deleted.
//
// The example displays the following output if run on a Unix-based system:
//      Test1: Value1
//
//      Test1 has been deleted.
Module Example
   Public Sub Main()
      Dim value As String 
      Dim toDelete As Boolean = False
      
      ' Check whether the environment variable exists.
      value = Environment.GetEnvironmentVariable("Test1")
      ' If necessary, create it.
      If value Is Nothing Then
         Environment.SetEnvironmentVariable("Test1", "Value1")
         toDelete = True
         
         ' Now retrieve it.
         value = Environment.GetEnvironmentVariable("Test1")
      End If
      ' Display the value.
      Console.WriteLine($"Test1: {value}")
      Console.WriteLine()
      
      ' Confirm that the value can only be retrieved from the process
      ' environment block if running on a Windows system.
      If Environment.OSVersion.Platform = PlatformID.Win32NT Then
         Console.WriteLine("Attempting to retrieve Test1 from:")
         For Each enumValue As EnvironmentVariableTarget In 
                           [Enum].GetValues(GetType(EnvironmentVariableTarget))
            value = Environment.GetEnvironmentVariable("Test1", enumValue)
            Console.WriteLine($"   {enumValue}: {If(value IsNot Nothing, "found", "not found")}")
         Next
         Console.WriteLine()
      End If

      ' If we've created it, now delete it.
      If toDelete Then 
         Environment.SetEnvironmentVariable("Test1", Nothing)
         ' Confirm the deletion.
         If Environment.GetEnvironmentVariable("Test1") = Nothing Then
            Console.WriteLine("Test1 has been deleted.")
         End If
      End If         
   End Sub
End Module
' The example displays the following output if run on a Windows system:
'      Test1: Value1
'
'      Attempting to retrieve Test1 from:
'         Process: found
'         User: not found
'         Machine: not found
'
'      Test1 has been deleted.
'
' The example displays the following output if run on a Unix-based system:
'      Test1: Value1
'
'      Test1 has been deleted.

Comentarios

El GetEnvironmentVariable(String) método recupera una variable de entorno solo del bloque de entorno del proceso actual.The GetEnvironmentVariable(String) method retrieves an environment variable from the environment block of the current process only. Es equivalente a llamar al GetEnvironmentVariable(String, EnvironmentVariableTarget) método con un target valor de EnvironmentVariableTarget.Process .It is equivalent to calling the GetEnvironmentVariable(String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.Process.

Para recuperar todas las variables de entorno junto con sus valores, llame al GetEnvironmentVariables método.To retrieve all environment variables along with their values, call the GetEnvironmentVariables method.

Los nombres de las variables de entorno distinguen mayúsculas de minúsculas en Linux y macOS, pero no distinguen mayúsculas de minúsculas en Windows.Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows.

En sistemas WindowsOn Windows systems

En los sistemas Windows, el bloque de entorno del proceso actual incluye:On Windows systems, the environment block of the current process includes:

  • Todas las variables de entorno que le proporciona el proceso primario que la creó.All environment variables that are provided to it by the parent process that created it. Por ejemplo, una aplicación .NET iniciada desde una ventana de consola hereda todas las variables de entorno de la ventana de la consola.For example, a .NET application launched from a console window inherits all of the console window's environment variables.

    Si no hay ningún proceso primario, se usan variables de entorno por equipo y por usuario en su lugar.If there is no parent process, per-machine and per-user environment variables are used instead. Por ejemplo, una nueva ventana de consola tiene todas las variables de entorno por equipo y por usuario definidas en el momento en que se inició.For example, a new console window has all per-machine and per-user environment variables defined at the time it was launched.

  • Cualquier variable agregada al bloque Process mientras el proceso se está ejecutando llamando al SetEnvironmentVariable(String, String) método o al SetEnvironmentVariable(String, String, EnvironmentVariableTarget) método con un target valor de EnvironmentVariableTarget.Process .Any variables added to the process block while the process is running by calling either the SetEnvironmentVariable(String, String) method or the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.Process. Estas variables de entorno se conservan hasta que finaliza la aplicación .NET.These environment variables persist until the .NET application terminates.

Si se crean variables de entorno después de que se haya iniciado el proceso, puede usar este método para recuperar solo las variables que se crearon llamando al SetEnvironmentVariable(String, String) método o al SetEnvironmentVariable(String, String, EnvironmentVariableTarget) método con un target valor de. EnvironmentVariableTarget.Process .If environment variables are created after the process has started, you can use this method to retrieve only those variables that were created by calling the SetEnvironmentVariable(String, String) method or the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a target value of .EnvironmentVariableTarget.Process.

En sistemas macOS y LinuxOn macOS and Linux systems

En macOS y Linux, el bloque de entorno del proceso actual incluye las siguientes variables de entorno:On macOS and Linux, the environment block of the current process includes the following environment variables:

.NET Core en macOS y Linux no admite variables de entorno por equipo o por usuario..NET Core on macOS and Linux does not support per-machine or per-user environment variables.

Consulte también

Se aplica a

GetEnvironmentVariable(String, EnvironmentVariableTarget)

Recupera el valor de una variable de entorno del proceso actual o de la clave del Registro del sistema operativo Windows para la máquina local o el usuario actual.Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.

public:
 static System::String ^ GetEnvironmentVariable(System::String ^ variable, EnvironmentVariableTarget target);
public static string? GetEnvironmentVariable (string variable, EnvironmentVariableTarget target);
public static string GetEnvironmentVariable (string variable, EnvironmentVariableTarget target);
static member GetEnvironmentVariable : string * EnvironmentVariableTarget -> string
Public Shared Function GetEnvironmentVariable (variable As String, target As EnvironmentVariableTarget) As String

Parámetros

variable
String

Nombre de una variable de entorno.The name of an environment variable.

target
EnvironmentVariableTarget

Uno de los valores de EnvironmentVariableTarget.One of the EnvironmentVariableTarget values. Solo se admite Process en .NET Core que se ejecute en sistemas basados en Unix.Only Process is supported on .NET Core running on Unix-bases systems.

Devoluciones

String

El valor de la variable de entorno especificada por los parámetros variable y target, o null si no se encuentra la variable de entorno.The value of the environment variable specified by the variable and target parameters, or null if the environment variable is not found.

Excepciones

variable es null.variable is null.

target no es un valor EnvironmentVariableTarget válido.target is not a valid EnvironmentVariableTarget value.

El autor de la llamada no tiene el permiso requerido para llevar a cabo esta operación.The caller does not have the required permission to perform this operation.

Ejemplos

En el ejemplo siguiente se crean variables de entorno para los EnvironmentVariableTarget.Process EnvironmentVariableTarget.User destinos, y Machine , se comprueba si el registro del sistema operativo contiene las variables de entorno de usuario y equipo y, a continuación, se eliminan las variables de entorno.The following example creates environment variables for the EnvironmentVariableTarget.Process, EnvironmentVariableTarget.User, and Machine targets, checks whether the operating system registry contains the user and machine environment variables, then deletes the environment variables. Dado que .NET en sistemas basados en UNIX no admite variables de entorno por usuario y por equipo, solo SetEnvironmentVariable(String, String) y SetEnvironmentVariable(String, String, EnvironmentVariableTarget) con un valor de EnvironmentVariableTarget.Process almacenar correctamente una variable de entorno en el bloque de entorno de proceso.Because .NET on Unix-based systems does not support per-user and per-machine environment variables, only SetEnvironmentVariable(String, String) and SetEnvironmentVariable(String, String, EnvironmentVariableTarget) with a value of EnvironmentVariableTarget.Process successfully store an environment variable to the process environment block.

using System;
using System.Collections;
using Microsoft.Win32;

class Sample
{
    public static void Main()
    {
        // Environment variable names for default, process, user, and machine targets.
        string defaultEnvVar = nameof(defaultEnvVar);
        string processEnvVar = nameof(processEnvVar);
        string userEnvVar = nameof(userEnvVar);
        string machineEnvVar = nameof(machineEnvVar);

        string dft = nameof(dft);
        string process = nameof(process);
        string user = nameof(user);
        string machine = nameof(machine);

        // Set the environment variable for each target.
        Console.WriteLine("Setting environment variables for each target...\n");
        // The default target (the current process).
        Environment.SetEnvironmentVariable(defaultEnvVar, dft);
        // The current process.
        Environment.SetEnvironmentVariable(processEnvVar, process,
                                           EnvironmentVariableTarget.Process);
        // The current user.
        Environment.SetEnvironmentVariable(userEnvVar, user,
                                           EnvironmentVariableTarget.User);
        // The local machine.
        Environment.SetEnvironmentVariable(machineEnvVar, machine,
                                           EnvironmentVariableTarget.Machine);

        // Define an array of environment variables.
        string[] envVars = { defaultEnvVar,processEnvVar, userEnvVar, machineEnvVar };

        // Try to get the environment variables from each target.
        // The default (no specified target).
        Console.WriteLine("Retrieving environment variables from the default target:");
        foreach (var envVar in envVars)
        {
          var value = Environment.GetEnvironmentVariable(envVar) ?? "(none)";
          Console.WriteLine($"   {envVar}: {value}");
        }
        // The process block.
        Console.WriteLine("\nRetrieving environment variables from the Process target:");
        foreach (var envVar in envVars)
        {
          var value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.Process) ?? "(none)";
          Console.WriteLine($"   {envVar}: {value}");
        }
        // The user block.
        Console.WriteLine("\nRetrieving environment variables from the User target:");
        foreach (var envVar in envVars)
        {
          var value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.User) ?? "(none)";
          Console.WriteLine($"   {envVar}: {value}");
        }
        // The machine block.
        Console.WriteLine("\nRetrieving environment variables from the Machine target:");
        foreach (var envVar in envVars)
        {
          var value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.Machine) ?? "(none)";
          Console.WriteLine($"   {envVar}: {value}");
        }

        // Delete the environment variable for each target.
        Console.WriteLine("\nDeleting environment variables for each target...\n");
        // The default target (the current process).
        Environment.SetEnvironmentVariable(defaultEnvVar, null);
        // The current process.
        Environment.SetEnvironmentVariable(processEnvVar, null,
                                           EnvironmentVariableTarget.Process);
        // The current user.
        Environment.SetEnvironmentVariable(userEnvVar, null,
                                           EnvironmentVariableTarget.User);
        // The local machine.
        Environment.SetEnvironmentVariable(machineEnvVar, null,
                                           EnvironmentVariableTarget.Machine);
    }
}
// The example displays the following output if run on a Windows system:
//      Setting environment variables for each target...
//
//      Retrieving environment variables from the default target:
//        defaultEnvVar: dft
//        processEnvVar: process
//        userEnvVar: user
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the Process target:
//        defaultEnvVar: dft
//        processEnvVar: process
//        userEnvVar: user
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the User target:
//        defaultEnvVar: (none)
//        processEnvVar: (none)
//        userEnvVar: user
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the Machine target:
//        defaultEnvVar: (none)
//        processEnvVar: (none)
//        userEnvVar: (none)
//        machineEnvVar: machine
//
//      Deleting environment variables for each target...
//
// The example displays the following output if run on a Unix-based system:
//
//      Setting environment variables for each target...
//
//      Retrieving environment variables from the default target:
//        defaultEnvVar: dft
//        processEnvVar: process
//        userEnvVar: (none)
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the Process target:
//        defaultEnvVar: dft
//        processEnvVar: process
//        userEnvVar: (none)
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the User target:
//        defaultEnvVar: (none)
//        processEnvVar: (none)
//        userEnvVar: (none)
//        machineEnvVar: (none)
//
//      Retrieving environment variables from the Machine target:
//        defaultEnvVar: (none)
//        processEnvVar: (none)
//        userEnvVar: (none)
//        machineEnvVar: (none)
//
//      Deleting environment variables for each target...
Imports System.Collections
Imports Microsoft.Win32

Module Sample 
    Public Sub Main() 
        ' Environment variable names for default, process, user, and machine targets.
        Dim defaultEnvVar As String = NameOf(defaultEnvVar)
        Dim processEnvVar As String = NameOf(processEnvVar)
        Dim userEnvVar As String = NameOf(userEnvVar)
        Dim machineEnvVar As String = NameOf(machineEnvVar)

        Dim dft As String = NameOf(dft)
        Dim process As String = NameOf(process)
        Dim user As String = NameOf(user)
        Dim machine As String = NameOf(machine)

        ' Set the environment variable for each target.
        Console.WriteLine("Setting environment variables for each target...")
        ' The default target (the current process).
        Environment.SetEnvironmentVariable(defaultEnvVar, dft)
        ' The current process.
        Environment.SetEnvironmentVariable(processEnvVar, process, 
                                           EnvironmentVariableTarget.Process)
        ' The current user.
        Environment.SetEnvironmentVariable(userEnvVar, user, 
                                           EnvironmentVariableTarget.User)
        ' The local machine.
        Environment.SetEnvironmentVariable(machineEnvVar, machine, 
                                           EnvironmentVariableTarget.Machine)
        Console.WriteLine()

        ' Define an array of environment variables.
        Dim envVars As String() = { defaultEnvVar, processEnvVar, userEnvVar, machineEnvVar }
        
        ' Try to get the environment variables from each target.
        ' The default (no specified target).
        Console.WriteLine("Retrieving environment variables from the default target:")
        For Each envVar in envVars
          Dim value = Environment.GetEnvironmentVariable(envVar)
          Console.WriteLine($"   {envVar}: {If(value IsNot Nothing, value, "(none)")}")
        Next
        Console.WriteLine()
        ' The process block.
        Console.WriteLine("Retrieving environment variables from the Process target:")
        For Each envVar in envVars
          Dim value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.Process)
          Console.WriteLine($"   {envVar}: {If(value IsNot Nothing, value, "(none)")}")
        Next
        Console.WriteLine()
        ' The user block.
        Console.WriteLine("Retrieving environment variables from the User target:")
        For Each envVar in envVars
          Dim value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.User)
          Console.WriteLine($"   {envVar}: {value}")
        Next
        Console.WriteLine()
        ' The machine block.
        Console.WriteLine("Retrieving environment variables from the Machine target:")
        For Each envVar in envVars
          Dim value = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.Machine)
          Console.WriteLine($"   {envVar}: {value}")
        Next
        Console.WriteLine()

        ' Delete the environment variable for each target.
        Console.WriteLine("Deleting environment variables for each target...")
        ' The default target (the current process).
        Environment.SetEnvironmentVariable(defaultEnvVar, Nothing)
        ' The current process.
        Environment.SetEnvironmentVariable(processEnvVar, Nothing, 
                                           EnvironmentVariableTarget.Process)
        ' The current user.
        Environment.SetEnvironmentVariable(userEnvVar, Nothing, 
                                           EnvironmentVariableTarget.User)
        ' The local machine.
        Environment.SetEnvironmentVariable(machineEnvVar, Nothing, 
                                           EnvironmentVariableTarget.Machine)
    End Sub
End Module
' The example displays the following output if run on a Windows system:
'      Setting environment variables for each target...
'
'      Retrieving environment variables from the default target:
'        defaultEnvVar: dft
'        processEnvVar: process
'        userEnvVar: user
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the Process target:
'        defaultEnvVar: dft
'        processEnvVar: process
'        userEnvVar: user
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the User target:
'        defaultEnvVar: (none)
'        processEnvVar: (none)
'        userEnvVar: user
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the Machine target:
'        defaultEnvVar: (none)
'        processEnvVar: (none)
'        userEnvVar: (none)
'        machineEnvVar: machine
'
'      Deleting environment variables for each target...
'
' The example displays the following output if run on a Unix-based system:
'
'      Setting environment variables for each target...
'
'      Retrieving environment variables from the default target:
'        defaultEnvVar: dft
'        processEnvVar: process
'        userEnvVar: (none)
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the Process target:
'        defaultEnvVar: dft
'        processEnvVar: process
'        userEnvVar: (none)
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the User target:
'        defaultEnvVar: (none)
'        processEnvVar: (none)
'        userEnvVar: (none)
'        machineEnvVar: (none)
'
'      Retrieving environment variables from the Machine target:
'        defaultEnvVar: (none)
'        processEnvVar: (none)
'        userEnvVar: (none)
'        machineEnvVar: (none)
'
'      Deleting environment variables for each target...

Comentarios

Para recuperar todas las variables de entorno junto con sus valores, llame al GetEnvironmentVariables método.To retrieve all environment variables along with their values, call the GetEnvironmentVariables method.

Los nombres de las variables de entorno distinguen mayúsculas de minúsculas en Linux y macOS, pero no distinguen mayúsculas de minúsculas en Windows.Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows.

En sistemas WindowsOn Windows systems

En Windows, el target parámetro especifica si la variable de entorno se recupera del proceso actual o de la clave del registro del sistema operativo Windows para el equipo local o el usuario actual.On Windows, the target parameter specifies whether the environment variable is retrieved from the current process or from the Windows operating system registry key for the current user or local machine. Todas las variables de entorno por usuario y por equipo se copian automáticamente en el bloque de entorno del proceso actual, al igual que cualquier otra variable de entorno que esté disponible para el proceso primario que creó el proceso de .NET.All per-user and per-machine environment variables are automatically copied into the environment block of the current process, as are any other environment variables that are available to the parent process that created the .NET process. Sin embargo, las variables de entorno solo se agregan al bloque de entorno del proceso actual llamando al SetEnvironmentVariable(String, String) método o al SetEnvironmentVariable(String, String, EnvironmentVariableTarget) método con un target valor de EnvironmentVariableTarget.Process Persist solo mientras dure el proceso.However, environment variables added only to the environment block of the current process by calling either the SetEnvironmentVariable(String, String) method or the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.Process persist only for the duration of the process.

En sistemas macOS y LinuxOn macOS and Linux systems

En macOS y Linux, el GetEnvironmentVariable(String, EnvironmentVariableTarget) método solo admite un target valor de EnvironmentVariableTarget.Process .On macOS and Linux, the GetEnvironmentVariable(String, EnvironmentVariableTarget) method supports a target value of EnvironmentVariableTarget.Process only. Las llamadas con un target valor de EnvironmentVariableTarget.Machine o EnvironmentVariableTarget.User no se admiten y devuelven null .Calls with a target value of EnvironmentVariableTarget.Machine or EnvironmentVariableTarget.User are not supported and return null.

Las variables de entorno por proceso son:Per-process environment variables are:

Consulte también

Se aplica a