次の方法で共有


Environment.GetEnvironmentVariables メソッド

すべての環境変数とその値を返します。

Public Shared Function GetEnvironmentVariables() As IDictionary
[C#]
public static IDictionary GetEnvironmentVariables();
[C++]
public: static IDictionary* GetEnvironmentVariables();
[JScript]
public static function GetEnvironmentVariables() : IDictionary;

戻り値

すべての環境変数とその値を保持した IDictionary 。システムで環境変数がサポートされていない場合には null 参照 (Visual Basic では Nothing) 。

解説

環境変数の名前および設定は、返された IDictionary にそれぞれキーおよび値として格納されています。

使用例

 
' Sample for the Environment.GetEnvironmentVariables method
Imports System
Imports System.Collections

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetEnvironmentVariables: ")
      Dim environmentVariables As IDictionary = Environment.GetEnvironmentVariables()
      Dim de As DictionaryEntry
      For Each de In  environmentVariables
         Console.WriteLine("  {0} = {1}", de.Key, de.Value)
      Next de
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'(Any result that is lengthy, specific to the machine on which this sample was tested, 
'or reveals information that should remain secure, has been omitted 
'and marked "!---OMITTED---!".)
'
'GetEnvironmentVariables: 
'  !---OMITTED---!
'

[C#] 
// Sample for the Environment.GetEnvironmentVariables method
using System;
using System.Collections;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("GetEnvironmentVariables: ");
    IDictionary    environmentVariables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry de in environmentVariables)
        {
        Console.WriteLine("  {0} = {1}", de.Key, de.Value);
        }
    }
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked "!---OMITTED---!".)

GetEnvironmentVariables: 
  !---OMITTED---!
*/

[C++] 
// Sample for the Environment::GetEnvironmentVariables method
#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;

int main() {
   Console::WriteLine();
   Console::WriteLine(S"GetEnvironmentVariables: ");
   IDictionary*    environmentVariables = Environment::GetEnvironmentVariables();
   IEnumerator* myEnum = environmentVariables->GetEnumerator();
   while (myEnum->MoveNext()) {
      DictionaryEntry* de = __try_cast<DictionaryEntry*>(myEnum->Current);

      Console::WriteLine(S" {0} = {1}", de->Key, de->Value);
   }
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked S"!---OMITTED---!".)

GetEnvironmentVariables:
!---OMITTED---!
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

.NET Framework セキュリティ:

参照

Environment クラス | Environment メンバ | System 名前空間 | GetEnvironmentVariable