EnvironmentVariableTarget 열거형

정의

set 또는 get 작업에서 환경 변수가 저장되거나 검색되는 위치를 지정합니다.Specifies the location where an environment variable is stored or retrieved in a set or get operation.

public enum class EnvironmentVariableTarget
[System.Runtime.InteropServices.ComVisible(true)]
public enum EnvironmentVariableTarget
type EnvironmentVariableTarget = 
Public Enum EnvironmentVariableTarget
상속
EnvironmentVariableTarget
특성

필드

Machine 2

환경 변수는 Windows 운영 체제 레지스트리의 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment 키에서 저장되거나 검색됩니다.The environment variable is stored or retrieved from the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment key in the Windows operating system registry. 이 값은 Windows 시스템에서만 실행되는 .NET 구현에 사용되어야 합니다.This value should be used on .NET implementations running on Windows systems only.

Process 0

환경 변수는 현재 프로세스와 연결된 환경 블록에서 저장되거나 검색됩니다.The environment variable is stored or retrieved from the environment block associated with the current process.

User 1

환경 변수는 Windows 운영 체제 레지스트리의 HKEY_CURRENT_USER\Environment 키에서 저장되거나 검색됩니다.The environment variable is stored or retrieved from the HKEY_CURRENT_USER\Environment key in the Windows operating system registry. 이 값은 Windows 시스템에서만 실행되는 .NET 구현에 사용되어야 합니다.This value should be used on .NET implementations running on Windows systems only.

예제

다음 예제에서는 환경 변수 EnvironmentVariableTarget 를 만들고, 검색 하 고, 삭제 하는 메서드에서 열거형을 사용 합니다.The following example uses the EnvironmentVariableTarget enumeration in methods that create, retrieve, and delete environment variables. 예제의 출력은 값을 EnvironmentVariableTarget 지정 하지 않고 저장 및 검색 되는 환경 변수가 현재 프로세스 (EnvironmentVariableTarget.Process)와 연결 된 환경 블록에 저장 됨을 보여 줍니다.The output from the example shows that environmnent variables stored and retrieved without specifying a EnvironmentVariableTarget value are stored in the environment block associated with the current process (EnvironmentVariableTarget.Process). Unix 기반 시스템의 예제 출력에는 이외의 EnvironmentVariableTarget.Process 값으로 환경 변수를 정의 하려는 시도가 무시 됨도 표시 됩니다.The example output from Unix-based systems also shows that attempts to define an environment variable with a value other than EnvironmentVariableTarget.Process is ignored.

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...

설명

EnvironmentVariableTarget 열거형의 특정 오버 로드에서 사용 되는 Environment.SetEnvironmentVariable, Environment.GetEnvironmentVariable, 및 Environment.GetEnvironmentVariables 위치 또는 대상으로 지정 하는 방법 이름과 환경 변수의 값을 저장 하거나 검색할 위치입니다.The EnvironmentVariableTarget enumeration is used by certain overloads of the Environment.SetEnvironmentVariable, Environment.GetEnvironmentVariable, and Environment.GetEnvironmentVariables methods to specify the location, or target, where the name and value of an environment variable is stored or retrieved.

대상은 다음 세 위치 중 하나일 수 있습니다.The target can be one of three locations:

  • 현재 프로세스와 연결 된 환경 블록 (EnvironmentVariableTarget.Process)입니다.The environment block associated with the current process (EnvironmentVariableTarget.Process).

    사용자는 set 작업에서 환경 변수를 만듭니다.The user creates the environment variable in a set operation. 프로세스 종료 되 면 운영 체제 프로세스의 환경 변수를 제거 합니다.When the process terminates, the operating system destroys the environment variable in that process.

  • 현재 사용자 (EnvironmentVariableTarget.User)와 연결 된 환경 변수에 대해 예약 된 Windows 운영 체제 레지스트리 키입니다.The Windows operating system registry key reserved for environment variables associated with the current user (EnvironmentVariableTarget.User).

    Windows 시스템에서 사용자가 설정 작업으로 환경 변수를 만들 때 운영 체제는 환경 변수를 시스템 레지스트리에 저장 하지만 현재 프로세스에는 저장 하지 않습니다.On Windows systems, when the user creates the environment variable in a set operation, the operating system stores the environment variable in the system registry, but not in the current process. 새 프로세스를 시작 하는 사용자, 운영 체제는 해당 프로세스 환경 변수 레지스트리에서 복사 합니다.If the user starts a new process, the operating system copies the environment variable from the registry to that process. 프로세스 종료 되 면 운영 체제 프로세스의 환경 변수를 제거 합니다.When the process terminates, the operating system destroys the environment variable in that process. 그러나 레지스트리 환경 변수는 사용자가 프로그래밍 방식으로 또는 운영 체제 도구를 사용 하 여 제거 될 때까지 유지 됩니다.However, the environment variable in the registry persists until the user removes it programmatically or by means of an operating system tool.

    Unix 기반 시스템에서를 사용 하 여 환경 변수 EnvironmentVariable.User 를 만들려는 시도는 아무런 영향을 주지 않으며를 사용 하 여 EnvironmentVariable.User 환경 변수를 검색 하려는 null 시도는 C#(에서 Nothing ) 또는 (Visual Basic)을 반환 합니다.On Unix-based systems, an attempt to create an enviroment variable with EnvironmentVariable.User has no effect, and an attempt to retrieve an enviroment variable using EnvironmentVariable.User returns null (in C#) or Nothing (in Visual Basic).

  • 로컬 컴퓨터 (EnvironmentVariableTarget.Machine)의 모든 사용자와 연결 된 환경 변수에 대해 예약 된 레지스트리 키입니다.The registry key reserved for environment variables associated with all users on the local machine (EnvironmentVariableTarget.Machine).

    사용자가 set 작업에서 환경 변수를 만들면 운영 체제, 시스템 레지스트리 있지만 현재 프로세스에 없는 환경 변수를 저장 합니다.When a user creates the environment variable in a set operation, the operating system stores the environment variable in the system registry, but not in the current process. 새 프로세스를 시작 하는 로컬 컴퓨터의 모든 사용자, 운영 체제는 해당 프로세스 환경 변수 레지스트리에서 복사 합니다.If any user on the local machine starts a new process, the operating system copies the environment variable from the registry to that process. 프로세스 종료 되 면 운영 체제 프로세스의 환경 변수를 제거 합니다.When the process terminates, the operating system destroys the environment variable in that process. 그러나 레지스트리 환경 변수는 사용자가 프로그래밍 방식으로 또는 운영 체제 도구를 사용 하 여 제거 될 때까지 유지 됩니다.However, the environment variable in the registry persists until a user removes it programmatically or by means of an operating system tool.

    Unix 기반 시스템에서를 사용 하 여 환경 변수 EnvironmentVariable.Machine 를 만들려는 시도는 아무런 영향을 주지 않으며를 사용 하 여 EnvironmentVariable.Machine 환경 변수를 검색 하려는 null 시도는 C#(에서 Nothing ) 또는 (Visual Basic)을 반환 합니다.On Unix-based systems, an attempt to create an enviroment variable with EnvironmentVariable.Machine has no effect, and an attempt to retrieve an enviroment variable using EnvironmentVariable.Machine returns null (in C#) or Nothing (in Visual Basic).

적용 대상