Environment.SetEnvironmentVariable 메서드

정의

환경 변수를 생성, 수정 또는 삭제합니다.Creates, modifies, or deletes an environment variable.

오버로드

SetEnvironmentVariable(String, String)

현재 프로세스에 저장되어 있는 환경 변수를 생성, 수정 또는 삭제합니다.Creates, modifies, or deletes an environment variable stored in the current process.

SetEnvironmentVariable(String, String, EnvironmentVariableTarget)

현재 프로세스 또는 현재 사용자나 로컬 컴퓨터에 예약된 Windows 운영 체제 레지스트리 키에 저장되어 있는 환경 변수를 생성, 수정 또는 삭제합니다.Creates, modifies, or deletes an environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.

SetEnvironmentVariable(String, String)

현재 프로세스에 저장되어 있는 환경 변수를 생성, 수정 또는 삭제합니다.Creates, modifies, or deletes an environment variable stored in the current process.

public:
 static void SetEnvironmentVariable(System::String ^ variable, System::String ^ value);
public static void SetEnvironmentVariable (string variable, string value);
public static void SetEnvironmentVariable (string variable, string? value);
static member SetEnvironmentVariable : string * string -> unit
Public Shared Sub SetEnvironmentVariable (variable As String, value As String)

매개 변수

variable
String

환경 변수의 이름입니다.The name of an environment variable.

value
String

variable에 할당할 값입니다.A value to assign to variable.

예외

variable이(가) null인 경우variable is null.

variable 에 빈 문자열, 초기 16진수 0 문자(0x00) 또는 등호("=")가 포함되어 있습니다.variable contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("=").

-또는--or-

variable 또는 value의 길이가 32,767자보다 크거나 같습니다.The length of variable or value is greater than or equal to 32,767 characters.

-또는--or-

이 작업을 실행하는 동안 오류가 발생했습니다.An error occurred during the execution of this operation.

호출자에게 이 작업을 수행하는 데 필요한 권한이 없습니다.The caller does not have the required permission to perform this operation.

예제

다음 예에서는 Test1 프로세스 환경 블록에서 이라는 환경 변수의 값을 검색 하려고 시도 합니다.The following example attempts to retrieve the value of an environment variable named Test1 from the process environment block. 변수가 없는 경우이 예에서는 변수를 만들고 해당 값을 검색 합니다.If the variable doesn't exist, the example creates the variable and retrieves its value. 이 예에서는 변수의 값을 표시 합니다.The example displays the value of the variable. Windows 시스템에서 실행 되는 .NET 구현의 경우 GetEnvironmentVariables(EnvironmentVariableTarget) 열거형의 각 멤버와 함께 메서드를 호출 EnvironmentVariableTarget 하 여 현재 프로세스 환경 블록 에서만 변수를 검색할 수 있도록 설정 합니다.For .NET implementations running on Windows systems, 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. Unix 기반 시스템의 .NET 구현은 process environment 블록의 변수만 지원 합니다. 마지막으로,이 예제에서는 변수를 만든 경우 삭제 합니다.(.NET implementations on Unix-based systems only support variables in the process environment block.) 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.

설명

이 메서드를 호출 하는 것은 SetEnvironmentVariable(String, String, EnvironmentVariableTarget) 인수에 값을 사용 하 여 오버 로드를 호출 하는 것과 같습니다 EnvironmentVariableTarget.Process target .Calling this method is equivalent to calling the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) overload with a value of EnvironmentVariableTarget.Process for the target argument.

value인수가 비어 있지 않은 경우 (빈 값 정의에 대 한이 섹션의 뒷부분에 나오는 환경 변수 삭제에 대 한 설명 참조) 매개 변수로 명명 된 환경 변수가 variable 존재 하지 않으면 환경 변수가 만들어지고의 내용이 할당 됩니다 value .If the value argument is not empty (see the discussion of deleting an environment variable later in this section for the definition of an empty value) and the environment variable named by the variable parameter does not exist, the environment variable is created and assigned the contents of value. 존재 하는 경우 해당 값이 수정 됩니다.If it does exist, its value is modified. 환경 변수는 현재 프로세스의 환경 블록 에서만 정의 되므로 프로세스가 종료 된 후에는 지속 되지 않습니다.Because the environment variable is defined in the environment block of the current process only, it does not persist after the process has ended.

variable에 초기 16 진수 0이 아닌 문자가 포함 된 경우 0 자 앞의 문자는 환경 변수 이름으로 간주 되 고 모든 후속 문자는 무시 됩니다.If variable contains a non-initial hexadecimal zero character, the characters before the zero character are considered the environment variable name and all subsequent characters are ignored.

value에 초기 16 진수 0이 아닌 문자가 포함 된 경우 0 문자 앞의 문자가 환경 변수에 할당 되 고 모든 후속 문자는 무시 됩니다.If value contains a non-initial hexadecimal zero character, the characters before the zero character are assigned to the environment variable and all subsequent characters are ignored.

value가 비어 있고에서 이름이 인 환경 변수가 있으면 variable 환경 변수가 삭제 됩니다.If value is empty and the environment variable named by variable exists, the environment variable is deleted. 이 없으면 variable 작업을 수행할 수 없더라도 오류가 발생 하지 않습니다.If variable does not exist, no error occurs even though the operation cannot be performed. value 는 다음 조건 중 하나에서 비어 있는 것으로 간주 됩니다.value is considered empty under any of the following conditions:

  • null입니다.It is null.

  • String.Empty입니다.It is String.Empty.

  • 값이 U + 0000 인 단일 문자로 구성 됩니다.It consists of a single character whose value is U+0000.

추가 정보

적용 대상

SetEnvironmentVariable(String, String, EnvironmentVariableTarget)

현재 프로세스 또는 현재 사용자나 로컬 컴퓨터에 예약된 Windows 운영 체제 레지스트리 키에 저장되어 있는 환경 변수를 생성, 수정 또는 삭제합니다.Creates, modifies, or deletes an environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.

public:
 static void SetEnvironmentVariable(System::String ^ variable, System::String ^ value, EnvironmentVariableTarget target);
public static void SetEnvironmentVariable (string variable, string? value, EnvironmentVariableTarget target);
public static void SetEnvironmentVariable (string variable, string value, EnvironmentVariableTarget target);
static member SetEnvironmentVariable : string * string * EnvironmentVariableTarget -> unit
Public Shared Sub SetEnvironmentVariable (variable As String, value As String, target As EnvironmentVariableTarget)

매개 변수

variable
String

환경 변수의 이름입니다.The name of an environment variable.

value
String

variable에 할당할 값입니다.A value to assign to variable.

target
EnvironmentVariableTarget

환경 변수의 위치를 지정하는 열거형 값 중 하나입니다.One of the enumeration values that specifies the location of the environment variable.

예외

variable이(가) null인 경우variable is null.

variable 에 빈 문자열, 초기 16진수 0 문자(0x00) 또는 등호("=")가 포함되어 있습니다.variable contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("=").

-또는--or-

variable의 길이가 32,767자보다 크거나 같은 경우The length of variable is greater than or equal to 32,767 characters.

-또는--or-

targetEnvironmentVariableTarget 열거형의 멤버가 아닙니다.target is not a member of the EnvironmentVariableTarget enumeration.

-또는--or-

targetMachine 또는 User이고, variable 의 길이가 255보다 크거나 같습니다.target is Machine or User, and the length of variable is greater than or equal to 255.

-또는--or-

targetProcess 이고 value 의 길이가 32,767자보다 크거나 같습니다.target is Process and the length of value is greater than or equal to 32,767 characters.

-또는--or-

이 작업을 실행하는 동안 오류가 발생했습니다.An error occurred during the execution of this operation.

호출자에게 이 작업을 수행하는 데 필요한 권한이 없습니다.The caller does not have the required permission to perform this operation.

예제

다음 예에서는, 및 대상에 대 한 환경 변수를 만들고, EnvironmentVariableTarget.Process EnvironmentVariableTarget.User 운영 체제 Machine 레지스트리가 사용자 및 시스템 환경 변수를 포함 하는지 확인 한 후 환경 변수를 삭제 합니다.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. Unix 기반 시스템의 .NET은 사용자 단위 및 컴퓨터별 환경 변수를 지원 하지 않으므로 SetEnvironmentVariable(String, String) 값이 인 및만 SetEnvironmentVariable(String, String, EnvironmentVariableTarget) EnvironmentVariableTarget.Process 환경 변수를 프로세스 환경 블록에 저장 합니다.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...

설명

메서드를 사용 하 여 SetEnvironmentVariable(String, String, EnvironmentVariableTarget) 현재 프로세스 (값)에 사용할 수 있는 환경 변수를 정의할 수 있습니다 Process .The SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method lets you define an environment variable that is available to the current process (the Process value). 현재 프로세스 환경에 고유한 환경 변수는 프로세스가 종료 될 때 까지만 유지 됩니다.Environment variables that are unique to the current process environment block persist only until the process ends.

또한 Windows 시스템에서는 메서드를 사용 하 여 SetEnvironmentVariable(String, String, EnvironmentVariableTarget) 컴퓨터에서 실행 되는 모든 프로세스 ( EnvironmentVariableTarget.Machine 값) 및 사용자가 실행 하는 모든 프로세스 (값)에 사용할 수 있는 환경 변수를 정의할 수 있습니다 EnvironmentVariableTarget.User .In addition, on Windows systems only, the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method lets you define an environment variable that is available to all processes that run on a machine (the EnvironmentVariableTarget.Machine value) and to all processes run by a user (the EnvironmentVariableTarget.User value). 컴퓨터별 및 사용자별 환경 변수는 현재 프로세스의 환경 블록에 복사 됩니다.Per-machine and per-user environment variables are copied into the environment block of the current process.

MacOS 및 Linux 시스템의 .NET Core에서 또는 값을 사용 하 여 메서드에 대 한 호출은 SetEnvironmentVariable(String, String, EnvironmentVariableTarget) EnvironmentVariableTarget.Machine 무시 됩니다 EnvironmentVariableTarget.User .On .NET Core on macOS and Linux systems, calls to the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a value of EnvironmentVariableTarget.Machine or EnvironmentVariableTarget.User are ignored.

value인수가 비어 있지 않은 경우 (빈 값 정의에 대 한이 섹션의 뒷부분에 나오는 환경 변수 삭제에 대 한 설명 참조), 인수에 의해 이름이 지정 된 환경 변수는 variable 존재 하지 않습니다. 환경 변수가 만들어지고의 내용이 할당 됩니다 value .If the value argument is not empty (see the discussion of deleting an environment variable later in this section for the definition of an empty value) and the environment variable named by the variable argument does not exist, the environment variable is created and assigned the contents of value. 존재 하는 경우 해당 값이 수정 됩니다.If it does exist, its value is modified.

variable에 초기 16 진수 0이 아닌 문자가 포함 된 경우 0 자 앞의 문자는 환경 변수 이름으로 간주 되 고 모든 후속 문자는 무시 됩니다.If variable contains a non-initial hexadecimal zero character, the characters before the zero character are considered the environment variable name and all subsequent characters are ignored.

value에 초기 16 진수 0이 아닌 문자가 포함 된 경우 0 문자 앞의 문자가 환경 변수에 할당 되 고 모든 후속 문자는 무시 됩니다.If value contains a non-initial hexadecimal zero character, the characters before the zero character are assigned to the environment variable and all subsequent characters are ignored.

value가 비어 있고에서 이름이 인 환경 변수가 있으면 variable 환경 변수가 삭제 됩니다.If value is empty and the environment variable named by variable exists, the environment variable is deleted. value 는 다음 조건 중 하나에서 비어 있는 것으로 간주 됩니다.value is considered empty under any of the following conditions:

  • null입니다.It is null.

  • String.Empty입니다.It is String.Empty.

  • 값이 U + 0000 인 단일 문자로 구성 됩니다.It consists of a single character whose value is U+0000.

이 없으면 variable 작업을 수행할 수 없더라도 오류가 발생 하지 않습니다.If variable does not exist, no error occurs although the operation cannot be performed. targetMachine 현재 프로세스나 사용자 뿐 아니라 전체 로컬 컴퓨터에 영향을 주는 환경 변수를 실수로 삭제할 수 있으므로 주의 해야 합니다.Be careful when target is Machine, because you can accidentally delete an environment variable that affects your entire local machine, not just the current process or user.

EnvironmentVariableTarget 및 Windows 시스템의 EnvironmentVariableTargetEnvironmentVariableTarget.Machine and EnvironmentVariableTarget.User on Windows systems

target이 인 경우 EnvironmentVariableTarget.User 환경 변수는 로컬 컴퓨터 레지스트리의 HKEY_CURRENT_USER\Environment 키에 저장 됩니다.If target is EnvironmentVariableTarget.User, the environment variable is stored in the HKEY_CURRENT_USER\Environment key of the local computer's registry. 또한 현재 사용자로 실행 중인 파일 탐색기의 인스턴스에 복사 됩니다.It is also copied to instances of File Explorer that are running as the current user. 그러면 사용자가 파일 탐색기에서 시작 하는 모든 새 프로세스가 환경 변수가 상속 됩니다.The environment variable is then inherited by any new processes that the user launches from File Explorer.

마찬가지로 target 가 인 경우 EnvironmentVariableTarget.Machine 환경 변수는 로컬 컴퓨터 레지스트리의 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment 키에 저장 됩니다.Similarly, if target is EnvironmentVariableTarget.Machine, the environment variable is stored in the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment key of the local computer's registry. 또한 파일 탐색기의 모든 인스턴스에 복사 됩니다.It is also copied to all instances of File Explorer. 그러면 환경 변수가 파일 탐색기에서 실행 되는 모든 새 프로세스에 의해 상속 됩니다.The environment variable is then inherited by any new processes that are launched from File Explorer.

경우 target 됩니다 User 또는 Machine에 Windows에서 다른 애플리케이션 설정 작업의 알림이 표시 됩니다 WM_SETTINGCHANGE 메시지입니다.If target is User or Machine, other applications are notified of the set operation by a Windows WM_SETTINGCHANGE message.

target가 또는 인 경우 EnvironmentVariableTarget.User EnvironmentVariableTarget.Machine 의 길이는 value 2048 자 미만으로 하는 것이 좋습니다.If target is EnvironmentVariableTarget.User or EnvironmentVariableTarget.Machine, we recommend that the length of value be less than 2048 characters.

추가 정보

적용 대상