Environment Environment Environment Environment Class

定義

現在の環境およびプラットフォームに関する情報、およびそれらを操作する手段を提供します。Provides information about, and means to manipulate, the current environment and platform. このクラスは継承できません。This class cannot be inherited.

public ref class Environment abstract sealed
[System.Runtime.InteropServices.ComVisible(true)]
public static class Environment
type Environment = class
Public Class Environment
継承
EnvironmentEnvironmentEnvironmentEnvironment
属性

次の例については、現在の環境の一覧を表示します。The following example demonstrates displays a list of information about the current environment.

// Sample for Environment class summary
using namespace System;
using namespace System::Collections;
int main()
{
   String^ str;
   String^ nl = Environment::NewLine;
   
   //
   Console::WriteLine();
   Console::WriteLine( "-- Environment members --" );
   
   //  Invoke this sample with an arbitrary set of command line arguments.
   Console::WriteLine( "CommandLine: {0}", Environment::CommandLine );
   array<String^>^arguments = Environment::GetCommandLineArgs();
   Console::WriteLine( "GetCommandLineArgs: {0}", String::Join( ", ", arguments ) );
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "CurrentDirectory: {0}", Environment::CurrentDirectory );
   Console::WriteLine( "ExitCode: {0}", Environment::ExitCode );
   Console::WriteLine( "HasShutdownStarted: {0}", Environment::HasShutdownStarted );
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "MachineName: {0}", Environment::MachineName );
   Console::WriteLine( "NewLine: {0}  first line {0}  second line {0}  third line", Environment::NewLine );
   Console::WriteLine( "OSVersion: {0}", Environment::OSVersion );
   Console::WriteLine( "StackTrace: ' {0}'", Environment::StackTrace );
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "SystemDirectory: {0}", Environment::SystemDirectory );
   Console::WriteLine( "TickCount: {0}", Environment::TickCount );
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "UserDomainName: {0}", Environment::UserDomainName );
   Console::WriteLine( "UserInteractive: {0}", Environment::UserInteractive );
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "UserName: {0}", Environment::UserName );
   Console::WriteLine( "Version: {0}", Environment::Version );
   Console::WriteLine( "WorkingSet: {0}", Environment::WorkingSet );
   
   //  No example for Exit(exitCode) because doing so would terminate this example.
   //  <-- Keep this information secure! -->
   String^ query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
   str = Environment::ExpandEnvironmentVariables( query );
   Console::WriteLine( "ExpandEnvironmentVariables: {0} {1}", nl, str );
   Console::WriteLine( "GetEnvironmentVariable: {0}  My temporary directory is {1}.", nl, Environment::GetEnvironmentVariable( "TEMP" ) );
   Console::WriteLine( "GetEnvironmentVariables: " );
   IDictionary^ environmentVariables = Environment::GetEnvironmentVariables();
   IEnumerator^ myEnum = environmentVariables->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ de = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( " {0} = {1}", de->Key, de->Value );
   }

   Console::WriteLine( "GetFolderPath: {0}", Environment::GetFolderPath( Environment::SpecialFolder::System ) );
   array<String^>^drives = Environment::GetLogicalDrives();
   Console::WriteLine( "GetLogicalDrives: {0}", String::Join( ", ", drives ) );
}

/*
This example produces results similar to the following:
(Any result that is lengthy or reveals information that should remain 
secure has been omitted and marked S"!---OMITTED---!".)

C:\>env0 ARBITRARY TEXT

-- Environment members --
CommandLine: env0 ARBITRARY TEXT
GetCommandLineArgs: env0, ARBITRARY, TEXT
CurrentDirectory: C:\Documents and Settings\!---OMITTED---!
ExitCode: 0
HasShutdownStarted: False
MachineName: !---OMITTED---!
NewLine:
  first line
  second line
  third line
OSVersion: Microsoft Windows NT 5.1.2600.0
StackTrace: '   at System::Environment::GetStackTrace(Exception e)
   at System::Environment::GetStackTrace(Exception e)
   at System::Environment::get_StackTrace()
   at Sample::Main()'
SystemDirectory: C:\WINNT\System32
TickCount: 17995355
UserDomainName: !---OMITTED---!
UserInteractive: True
UserName: !---OMITTED---!
Version: !---OMITTED---!
WorkingSet: 5038080
ExpandEnvironmentVariables:
  My system drive is C: and my system root is C:\WINNT
GetEnvironmentVariable:
  My temporary directory is C:\DOCUME~1\!---OMITTED---!\LOCALS~1\Temp.
GetEnvironmentVariables:
  !---OMITTED---!
GetFolderPath: C:\WINNT\System32
GetLogicalDrives: A:\, C:\, D:\

*/
// Sample for Environment class summary
using System;
using System.Collections;

class Sample
{
    public static void Main()
    {
        string str;
        string nl = Environment.NewLine;
        //
        Console.WriteLine();
        Console.WriteLine("-- Environment members --");

        //  Invoke this sample with an arbitrary set of command line arguments.
        Console.WriteLine("CommandLine: {0}", Environment.CommandLine);

        string[] arguments = Environment.GetCommandLineArgs();
        Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));

        //  <-- Keep this information secure! -->
        Console.WriteLine("CurrentDirectory: {0}", Environment.CurrentDirectory);

        Console.WriteLine("ExitCode: {0}", Environment.ExitCode);

        Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted);

        //  <-- Keep this information secure! -->
        Console.WriteLine("MachineName: {0}", Environment.MachineName);

        Console.WriteLine("NewLine: {0}  first line{0}  second line{0}  third line",
                              Environment.NewLine);

        Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());

        Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);

        //  <-- Keep this information secure! -->
        Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory);

        Console.WriteLine("TickCount: {0}", Environment.TickCount);

        //  <-- Keep this information secure! -->
        Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName);

        Console.WriteLine("UserInteractive: {0}", Environment.UserInteractive);

        //  <-- Keep this information secure! -->
        Console.WriteLine("UserName: {0}", Environment.UserName);

        Console.WriteLine("Version: {0}", Environment.Version.ToString());

        Console.WriteLine("WorkingSet: {0}", Environment.WorkingSet);

        //  No example for Exit(exitCode) because doing so would terminate this example.

        //  <-- Keep this information secure! -->
        string query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
        str = Environment.ExpandEnvironmentVariables(query);
        Console.WriteLine("ExpandEnvironmentVariables: {0}  {1}", nl, str);

        Console.WriteLine("GetEnvironmentVariable: {0}  My temporary directory is {1}.", nl,
                               Environment.GetEnvironmentVariable("TEMP"));

        Console.WriteLine("GetEnvironmentVariables: ");
        IDictionary environmentVariables = Environment.GetEnvironmentVariables();
        foreach (DictionaryEntry de in environmentVariables)
        {
            Console.WriteLine("  {0} = {1}", de.Key, de.Value);
        }

        Console.WriteLine("GetFolderPath: {0}",
                     Environment.GetFolderPath(Environment.SpecialFolder.System));

        string[] drives = Environment.GetLogicalDrives();
        Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
    }
}
/*
This example produces results similar to the following:
(Any result that is lengthy or reveals information that should remain 
secure has been omitted and marked "!---OMITTED---!".)

C:\>env0 ARBITRARY TEXT

-- Environment members --
CommandLine: env0 ARBITRARY TEXT
GetCommandLineArgs: env0, ARBITRARY, TEXT
CurrentDirectory: C:\Documents and Settings\!---OMITTED---!
ExitCode: 0
HasShutdownStarted: False
MachineName: !---OMITTED---!
NewLine:
  first line
  second line
  third line
OSVersion: Microsoft Windows NT 5.1.2600.0
StackTrace: '   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.get_StackTrace()
   at Sample.Main()'
SystemDirectory: C:\WINNT\System32
TickCount: 17995355
UserDomainName: !---OMITTED---!
UserInteractive: True
UserName: !---OMITTED---!
Version: !---OMITTED---!
WorkingSet: 5038080
ExpandEnvironmentVariables:
  My system drive is C: and my system root is C:\WINNT
GetEnvironmentVariable:
  My temporary directory is C:\DOCUME~1\!---OMITTED---!\LOCALS~1\Temp.
GetEnvironmentVariables: 
  !---OMITTED---!
GetFolderPath: C:\WINNT\System32
GetLogicalDrives: A:\, C:\, D:\

*/
' Sample for Environment class summary
Imports System
Imports System.Collections

Class Sample
   Public Shared Sub Main()
      Dim str As [String]
      Dim nl As [String] = Environment.NewLine
      '
      Console.WriteLine()
      Console.WriteLine("-- Environment members --")
      
      '  Invoke this sample with an arbitrary set of command line arguments.
      Console.WriteLine("CommandLine: {0}", Environment.CommandLine)
      
      Dim arguments As [String]() = Environment.GetCommandLineArgs()
      Console.WriteLine("GetCommandLineArgs: {0}", [String].Join(", ", arguments))
      
      '  <-- Keep this information secure! -->
      Console.WriteLine("CurrentDirectory: {0}", Environment.CurrentDirectory)
      
      Console.WriteLine("ExitCode: {0}", Environment.ExitCode)
      
      Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted)
      
      '  <-- Keep this information secure! -->
      Console.WriteLine("MachineName: {0}", Environment.MachineName)
      
      Console.WriteLine("NewLine: {0}  first line{0}  second line{0}" & _
                        "  third line", Environment.NewLine)
      
      Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString())
      
      Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace)
      
      '  <-- Keep this information secure! -->
      Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory)
      
      Console.WriteLine("TickCount: {0}", Environment.TickCount)
      
      '  <-- Keep this information secure! -->
      Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName)
      
      Console.WriteLine("UserInteractive: {0}", Environment.UserInteractive)
      
      '  <-- Keep this information secure! -->
      Console.WriteLine("UserName: {0}", Environment.UserName)
      
      Console.WriteLine("Version: {0}", Environment.Version.ToString())
      
      Console.WriteLine("WorkingSet: {0}", Environment.WorkingSet)
      
      '  No example for Exit(exitCode) because doing so would terminate this example.

      '  <-- Keep this information secure! -->
      Dim query As [String] = "My system drive is %SystemDrive% and my" & _
                              " system root is %SystemRoot%"
      str = Environment.ExpandEnvironmentVariables(query)
      Console.WriteLine("ExpandEnvironmentVariables: {0}  {1}", nl, str)
      
      Console.WriteLine("GetEnvironmentVariable: {0}  My temporary directory is {1}.", _
                        nl, Environment.GetEnvironmentVariable("TEMP"))
      
      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
      
      Console.WriteLine("GetFolderPath: {0}", _
              Environment.GetFolderPath(Environment.SpecialFolder.System))
      
      Dim drives As [String]() = Environment.GetLogicalDrives()
      Console.WriteLine("GetLogicalDrives: {0}", [String].Join(", ", drives))
   End Sub 'Main
End Class 'Sample
'
'This example produces results similar to the following:
'(Any result that is lengthy or reveals information that should remain 
'secure has been omitted and marked "!---OMITTED---!".)
'
'C:\>env0 ARBITRARY TEXT
'
'-- Environment members --
'CommandLine: env0 ARBITRARY TEXT
'GetCommandLineArgs: env0, ARBITRARY, TEXT
'CurrentDirectory: C:\Documents and Settings\!---OMITTED---!
'ExitCode: 0
'HasShutdownStarted: False
'MachineName: !---OMITTED---!
'NewLine:
'  first line
'  second line
'  third line
'OSVersion: Microsoft Windows NT 5.1.2600.0
'StackTrace: '   at System.Environment.GetStackTrace(Exception e)
'   at System.Environment.GetStackTrace(Exception e)
'   at System.Environment.get_StackTrace()
'   at Sample.Main()'
'SystemDirectory: C:\WINNT\System32
'TickCount: 17995355
'UserDomainName: !---OMITTED---!
'UserInteractive: True
'UserName: !---OMITTED---!
'Version: !---OMITTED---!
'WorkingSet: 5038080
'ExpandEnvironmentVariables:
'  My system drive is C: and my system root is C:\WINNT
'GetEnvironmentVariable:
'  My temporary directory is C:\DOCUME~1\!---OMITTED---!\LOCALS~1\Temp.
'GetEnvironmentVariables: 
'  !---OMITTED---!
'GetFolderPath: C:\WINNT\System32
'GetLogicalDrives: A:\, C:\, D:\
'

注釈

使用して、Environmentシステムの起動、および共通言語ランタイムのバージョン以降のコマンドライン引数、終了コード、環境変数の設定、コール スタック、時間の内容などの情報を取得するクラス。Use the Environment class to retrieve information such as command-line arguments, the exit code, environment variable settings, contents of the call stack, time since last system boot, and the version of the common language runtime.

プロパティ

CommandLine CommandLine CommandLine CommandLine

このプロセス用のコマンド ラインを取得します。Gets the command line for this process.

CurrentDirectory CurrentDirectory CurrentDirectory CurrentDirectory

現在の作業ディレクトリの完全修飾パスを取得または設定します。Gets or sets the fully qualified path of the current working directory.

CurrentManagedThreadId CurrentManagedThreadId CurrentManagedThreadId CurrentManagedThreadId

現在のマネージド スレッドの一意の識別子を取得します。Gets a unique identifier for the current managed thread.

ExitCode ExitCode ExitCode ExitCode

プロセスの終了コードを取得または設定します。Gets or sets the exit code of the process.

HasShutdownStarted HasShutdownStarted HasShutdownStarted HasShutdownStarted

現在のアプリケーション ドメインがアンロード中か、または共通言語ランタイム (CLR) がシャットダウン中かどうかを示す値を取得します。Gets a value that indicates whether the current application domain is being unloaded or the common language runtime (CLR) is shutting down.

Is64BitOperatingSystem Is64BitOperatingSystem Is64BitOperatingSystem Is64BitOperatingSystem

現在のオペレーティング システムが 64 ビット オペレーティング システムかどうかを判断します。Determines whether the current operating system is a 64-bit operating system.

Is64BitProcess Is64BitProcess Is64BitProcess Is64BitProcess

現在のプロセスが 64 ビット プロセスかどうかを判断します。Determines whether the current process is a 64-bit process.

MachineName MachineName MachineName MachineName

ローカル コンピューターの NetBIOS 名を取得します。Gets the NetBIOS name of this local computer.

NewLine NewLine NewLine NewLine

この環境で定義されている改行文字列を取得します。Gets the newline string defined for this environment.

OSVersion OSVersion OSVersion OSVersion

現在のプラットフォーム ID とバージョン番号を格納している OperatingSystem オブジェクトを取得します。Gets an OperatingSystem object that contains the current platform identifier and version number.

ProcessorCount ProcessorCount ProcessorCount ProcessorCount

現在のコンピューター上のプロセッサ数を取得します。Gets the number of processors on the current machine.

StackTrace StackTrace StackTrace StackTrace

現在のスタック トレース情報を取得します。Gets current stack trace information.

SystemDirectory SystemDirectory SystemDirectory SystemDirectory

システム ディレクトリの絶対パスを取得します。Gets the fully qualified path of the system directory.

SystemPageSize SystemPageSize SystemPageSize SystemPageSize

オペレーティング システムのメモリ ページ内にあるバイト数を取得します。Gets the number of bytes in the operating system's memory page.

TickCount TickCount TickCount TickCount

システム起動後のミリ秒単位の経過時間を取得します。Gets the number of milliseconds elapsed since the system started.

UserDomainName UserDomainName UserDomainName UserDomainName

現在のユーザーに関連付けられているネットワーク ドメイン名を取得します。Gets the network domain name associated with the current user.

UserInteractive UserInteractive UserInteractive UserInteractive

現在のプロセスがユーザー対話モードで実行されているかどうかを示す値を取得します。Gets a value indicating whether the current process is running in user interactive mode.

UserName UserName UserName UserName

現在オペレーティング システムにログオンしている人のユーザー名を取得します。Gets the user name of the person who is currently logged on to the operating system.

Version Version Version Version

共通言語ランタイムのメジャー バージョン番号、マイナー バージョン番号、ビルド番号、およびリビジョン番号を記述する Version オブジェクトを取得します。Gets a Version object that describes the major, minor, build, and revision numbers of the common language runtime.

WorkingSet WorkingSet WorkingSet WorkingSet

プロセス コンテキストに割り当てられる物理メモリ量を取得します。Gets the amount of physical memory mapped to the process context.

メソッド

Exit(Int32) Exit(Int32) Exit(Int32) Exit(Int32)

このプロセスを終了し、オペレーティング システムに終了コードを返します。Terminates this process and returns an exit code to the operating system.

ExpandEnvironmentVariables(String) ExpandEnvironmentVariables(String) ExpandEnvironmentVariables(String) ExpandEnvironmentVariables(String)

指定した文字列に埋め込まれている各環境変数の名前を、その変数の値を表す文字列で置換し、置換後の文字列全体を返します。Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, then returns the resulting string.

FailFast(String) FailFast(String) FailFast(String) FailFast(String)

メッセージを Windows アプリケーションのイベント ログに書き込んだ直後にプロセスを終了させ、Microsoft に送信するエラー レポートにそのメッセージを含めます。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft.

FailFast(String, Exception) FailFast(String, Exception) FailFast(String, Exception) FailFast(String, Exception)

メッセージを Windows アプリケーションのイベント ログに書き込んだ直後にプロセスを終了させ、Microsoft に送信するエラー レポートにそのメッセージと例外情報を含めます。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and exception information in error reporting to Microsoft.

GetCommandLineArgs() GetCommandLineArgs() GetCommandLineArgs() GetCommandLineArgs()

現在のプロセスに対するコマンド ライン引数を格納している文字列配列を返します。Returns a string array containing the command-line arguments for the current process.

GetEnvironmentVariable(String) GetEnvironmentVariable(String) GetEnvironmentVariable(String) GetEnvironmentVariable(String)

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

GetEnvironmentVariable(String, EnvironmentVariableTarget) GetEnvironmentVariable(String, EnvironmentVariableTarget) GetEnvironmentVariable(String, EnvironmentVariableTarget) 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.

GetEnvironmentVariables() GetEnvironmentVariables() GetEnvironmentVariables() GetEnvironmentVariables()

すべての環境変数の名前と値を現在のプロセスから取得します。Retrieves all environment variable names and their values from the current process.

GetEnvironmentVariables(EnvironmentVariableTarget) GetEnvironmentVariables(EnvironmentVariableTarget) GetEnvironmentVariables(EnvironmentVariableTarget) GetEnvironmentVariables(EnvironmentVariableTarget)

現在のプロセスから、または Windows オペレーティング システムのレジストリ キー (現在のユーザー用に予約されているレジストリ キーまたはローカル コンピューター用に予約されているレジストリ キー) から、すべての環境変数の名前と値を取得します。Retrieves all environment variable names and their values from the current process, or from the Windows operating system registry key for the current user or local machine.

GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder)

指定した列挙体によって識別されるシステムの特別なフォルダーへのパスを取得します。Gets the path to the system special folder that is identified by the specified enumeration.

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

指定した列挙体によって識別されるシステムの特別なフォルダーへのパスを取得します。指定したオプションを使用して特別なフォルダーにアクセスします。Gets the path to the system special folder that is identified by the specified enumeration, and uses a specified option for accessing special folders.

GetLogicalDrives() GetLogicalDrives() GetLogicalDrives() GetLogicalDrives()

現在のコンピューターの論理ドライブの名前を格納している文字列の配列を返します。Returns an array of string containing the names of the logical drives on the current computer.

SetEnvironmentVariable(String, String) SetEnvironmentVariable(String, String) SetEnvironmentVariable(String, String) SetEnvironmentVariable(String, String)

現在のプロセスに格納されている環境変数を作成、変更、または削除します。Creates, modifies, or deletes an environment variable stored in the current process.

SetEnvironmentVariable(String, String, EnvironmentVariableTarget) SetEnvironmentVariable(String, String, EnvironmentVariableTarget) SetEnvironmentVariable(String, String, EnvironmentVariableTarget) 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.

適用対象