Environment.GetEnvironmentVariable メソッド

定義

環境変数の値を取得します。Retrieves the value of an environment variable.

オーバーロード

GetEnvironmentVariable(String)

現在のプロセスから環境変数の値を取得します。Retrieves the value of an environment variable from the current process.

GetEnvironmentVariable(String, EnvironmentVariableTarget)

環境変数の値を取得します。取得する場所として、現在のプロセス、現在のユーザー用に予約されている Windows オペレーティング システムのレジストリ キー、および、ローカル コンピューター用に予約されているレジストリ キーのいずれかを選択できます。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)

現在のプロセスから環境変数の値を取得します。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);
static member GetEnvironmentVariable : string -> string
Public Shared Function GetEnvironmentVariable (variable As String) As String

パラメーター

variable
String

環境変数の名前。The name of the environment variable.

戻り値

variable で指定された環境変数の値。環境変数が見つからない場合は nullThe value of the environment variable specified by variable, or null if the environment variable is not found.

例外

variablenullです。variable is null.

呼び出し元に、この操作を実行するために必要なアクセス許可がありません。The caller does not have the required permission to perform this operation.

次の例では、GetEnvironmentVariable メソッドを使用して、Windows ディレクトリのパスを含む windir 環境変数を取得します。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.

次の例では、プロセス環境ブロックから 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 its and retrieves its value. この例では、変数の値が表示されます。The example displays the value of the variable. この例では、変数を作成した場合、EnvironmentVariableTarget 列挙体の各メンバーと共に GetEnvironmentVariables(EnvironmentVariableTarget) メソッドを呼び出して、現在のプロセス環境ブロックからのみ変数を取得できることを確立します。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. 最後に、この例で変数を作成した場合は、変数が削除されます。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.

注釈

@No__t-0 メソッドは、現在のプロセスの環境ブロックから環境変数を取得します。The GetEnvironmentVariable(String) method retrieves an environment variable from the environment block of the current process only. これは、EnvironmentVariableTarget.Processtarget の値を使用して GetEnvironmentVariable(String, EnvironmentVariableTarget) メソッドを呼び出すことと同じです。It is equivalent to calling the GetEnvironmentVariable(String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.Process.

すべての環境変数をその値と共に取得するには、GetEnvironmentVariables メソッドを呼び出します。To retrieve all environment variables along with their values, call the GetEnvironmentVariables method.

環境変数名は Linux と macOS では大文字と小文字が区別されますが、Windows では大文字と小文字が区別されません。Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows.

Windows システムの場合On Windows systems

Windows システムでは、現在のプロセスの環境ブロックには次のものが含まれます。On Windows systems, the environment block of the current process includes:

  • 作成元の親プロセスによって提供されるすべての環境変数。All environment variables that are provided to it by the parent process that created it. たとえば、コンソールウィンドウから起動した .NET アプリケーションは、コンソールウィンドウの環境変数をすべて継承します。For example, a .NET application launched from a console window inherits all of the console window's environment variables.

    親プロセスがない場合は、コンピューターごとおよびユーザーごとの環境変数が代わりに使用されます。If there is no parent process, per-machine and per-user environment variables are used instead. たとえば、新しいコンソールウィンドウには、起動時にコンピューターごとおよびユーザーごとの環境変数が定義されています。For example, a new console window has all per-machine and per-user environment variables defined at the time it was launched.

  • プロセスの実行中にプロセスブロックに追加されたすべての変数。 target の値が EnvironmentVariableTarget.ProcessSetEnvironmentVariable(String, String) メソッドまたは SetEnvironmentVariable(String, String, EnvironmentVariableTarget) メソッドを呼び出します。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. これらの環境変数は、.NET アプリケーションが終了するまで保持されます。These environment variables persist until the .NET application terminates.

プロセスの開始後に環境変数が作成された場合は、このメソッドを使用して、SetEnvironmentVariable(String, String) メソッドを呼び出すことによって作成された変数、または target の値がである @no__t メソッドを呼び出すことによって作成された変数のみを取得でき @no__t ます。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.

MacOS および Linux システムの場合On macOS and Linux systems

MacOS と Linux では、現在のプロセスの環境ブロックに次の環境変数が含まれています。On macOS and Linux, the environment block of the current process includes the following environment variables:

MacOS および Linux 上の .NET Core では、コンピューターごとまたはユーザーごとの環境変数はサポートされていません。.NET Core on macOS and Linux does not support per-machine or per-user environment variables.

セキュリティ

EnvironmentPermission
variable の値を読み取る機能。for the ability to read the value of variable. 関連付けられた列挙型: ReadAssociated enumeration: Read

こちらもご覧ください

GetEnvironmentVariable(String, EnvironmentVariableTarget)

環境変数の値を取得します。取得する場所として、現在のプロセス、現在のユーザー用に予約されている Windows オペレーティング システムのレジストリ キー、および、ローカル コンピューター用に予約されているレジストリ キーのいずれかを選択できます。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);
static member GetEnvironmentVariable : string * EnvironmentVariableTarget -> string
Public Shared Function GetEnvironmentVariable (variable As String, target As EnvironmentVariableTarget) As String

パラメーター

variable
String

環境変数の名前。The name of an environment variable.

target
EnvironmentVariableTarget

EnvironmentVariableTarget 値のいずれか 1 つ。One of the EnvironmentVariableTarget values. Unix ベースのシステムで実行される .NET Core では、Process のみがサポートされています。Only Process is supported on .NET Core running on Unix-bases systems.

戻り値

variable パラメーターと target パラメーターで指定された環境変数の値。環境変数が見つからない場合は nullThe value of the environment variable specified by the variable and target parameters, or null if the environment variable is not found.

例外

variablenullです。variable is null.

target は有効な EnvironmentVariableTarget 値ではありません。target is not a valid EnvironmentVariableTarget value.

呼び出し元に、この操作を実行するために必要なアクセス許可がありません。The caller does not have the required permission to perform this operation.

次の例では、EnvironmentVariableTarget.ProcessEnvironmentVariableTarget.User、および @no__t 2 のターゲットの環境変数を作成し、オペレーティングシステムのレジストリにユーザーとコンピューターの環境変数が含まれているかどうかを確認してから、環境変数を削除します。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 はユーザー単位およびコンピューター単位の環境変数をサポートしていないため、EnvironmentVariableTarget.Process の値を持つ SetEnvironmentVariable(String, String)SetEnvironmentVariable(String, String, EnvironmentVariableTarget) のみが正常にプロセス環境ブロックに環境変数を格納します。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...

注釈

すべての環境変数をその値と共に取得するには、GetEnvironmentVariables メソッドを呼び出します。To retrieve all environment variables along with their values, call the GetEnvironmentVariables method.

環境変数名は Linux と macOS では大文字と小文字が区別されますが、Windows では大文字と小文字が区別されません。Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows.

Windows システムの場合On Windows systems

Windows では、target パラメーターは、現在のプロセスから、または現在のユーザーまたはローカルコンピューターの Windows オペレーティングシステムのレジストリキーから環境変数を取得するかどうかを指定します。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. .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. ただし、環境変数は、現在のプロセスの環境ブロックにのみ追加されます。そのためには、SetEnvironmentVariable(String, String) メソッドまたは SetEnvironmentVariable(String, String, EnvironmentVariableTarget) @no__t @no__t メソッドのいずれかを呼び出します。これは、プロセスの期間だけ保持されます。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.

MacOS および Linux システムの場合On macOS and Linux systems

MacOS と Linux では、GetEnvironmentVariable(String, EnvironmentVariableTarget) メソッドは EnvironmentVariableTarget.Process の @no__t の値のみをサポートしています。On macOS and Linux, the GetEnvironmentVariable(String, EnvironmentVariableTarget) method supports a target value of EnvironmentVariableTarget.Process only. @No__t-1 または EnvironmentVariableTarget.User の @no__t 0 の値を持つ呼び出しはサポートされていないため、null を返します。Calls with a target value of EnvironmentVariableTarget.Machine or EnvironmentVariableTarget.User are not supported and return null.

プロセスごとの環境変数は次のとおりです。Per-process environment variables are:

  • 親プロセスから継承されたもの。通常は、dotnet.exe を呼び出すか、.NET アプリケーションを起動するために使用されるシェルです。Those inherited from the parent process, typically the shell used to invoke dotnet.exe or to launch the .NET application.

  • @No__t-0 メソッドまたは target の値が EnvironmentVariableTarget.Process の @no__t を呼び出すことによって定義されたメソッド。Those defined by calling either the SetEnvironmentVariable(String, String) method or the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.Process. これらの環境変数は、@no__t 0 のプロセスまたは .NET アプリケーションが終了するまで保持されます。These environment variables persist only until the dotnet process or the .NET application terminates.

セキュリティ

EnvironmentPermission

@no__t の値を読み取る機能の場合は、-1 が Process (関連付けられている列挙型: Read) の場合は 0 @no__t。for the ability to read the value of variable if target is Process (Associated enumeration: Read), oror targetUser または Machine (関連付けられている列挙型: Unrestricted) の場合、環境変数へのフルアクセス。for full access to environment variables if target is User or Machine (Associated enumeration: Unrestricted).

こちらもご覧ください

適用対象