Environment Sınıf

Tanım

İle ilgili bilgi sağlar ve geçerli ortamı ve platformu işlemek demektir.Provides information about, and means to manipulate, the current environment and platform. Bu sınıf devralınamaz.This class cannot be inherited.

public ref class Environment abstract sealed
public ref class Environment sealed
public static class Environment
public sealed class Environment
[System.Runtime.InteropServices.ComVisible(true)]
public static class Environment
type Environment = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type Environment = class
Public Class Environment
Public NotInheritable Class Environment
Devralma
Environment
Öznitelikler

Örnekler

Aşağıdaki örnek, geçerli ortamla ilgili bilgilerin bir listesini görüntüler.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.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
End Class
'
'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:\
'

Açıklamalar

EnvironmentKomut satırı bağımsız değişkenleri, çıkış kodu, ortam değişken ayarları, çağrı yığınının içeriği, son Sistem önyüklemesinden bu yana geçen süre ve ortak dil çalışma zamanının sürümü gibi bilgileri almak için sınıfını kullanın.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.

Özellikler

CommandLine

Bu işlem için komut satırını alır.Gets the command line for this process.

CurrentDirectory

Geçerli çalışma dizininin tam yolunu alır veya ayarlar.Gets or sets the fully qualified path of the current working directory.

CurrentManagedThreadId

Geçerli yönetilen iş parçacığı için benzersiz bir tanımlayıcı alır.Gets a unique identifier for the current managed thread.

ExitCode

İşlemin çıkış kodunu alır veya ayarlar.Gets or sets the exit code of the process.

HasShutdownStarted

Geçerli uygulama etki alanının bellekten kaldırılmadığını veya ortak dil çalışma zamanı (CLR) kapandığını belirten bir değer alır.Gets a value that indicates whether the current application domain is being unloaded or the common language runtime (CLR) is shutting down.

Is64BitOperatingSystem

Geçerli işletim sisteminin 64 bitlik bir işletim sistemi olup olmadığını gösteren bir değer alır.Gets a value that indicates whether the current operating system is a 64-bit operating system.

Is64BitProcess

Geçerli işlemin 64 bitlik bir işlem olup olmadığını gösteren bir değer alır.Gets a value that indicates whether the current process is a 64-bit process.

MachineName

Bu yerel bilgisayarın NetBIOS adını alır.Gets the NetBIOS name of this local computer.

NewLine

Bu ortam için tanımlanan yeni satır dizesini alır.Gets the newline string defined for this environment.

OSVersion

Geçerli platform tanımlayıcısı ve sürüm numarasını alır.Gets the current platform identifier and version number.

ProcessId

Geçerli işlemin benzersiz tanımlayıcısını alır.Gets the unique identifier for the current process.

ProcessorCount

Geçerli makinedeki işlemci sayısını alır.Gets the number of processors on the current machine.

StackTrace

Geçerli yığın izleme bilgilerini alır.Gets current stack trace information.

SystemDirectory

Sistem dizininin tam yolunu alır.Gets the fully qualified path of the system directory.

SystemPageSize

İşletim sisteminin bellek sayfasındaki bayt sayısını alır.Gets the number of bytes in the operating system's memory page.

TickCount

Sistemin başlatılmasından bu yana geçen milisaniye sayısını alır.Gets the number of milliseconds elapsed since the system started.

TickCount64

Sistemin başlatılmasından bu yana geçen milisaniye sayısını alır.Gets the number of milliseconds elapsed since the system started.

UserDomainName

Geçerli kullanıcıyla ilişkili ağ etki alanı adını alır.Gets the network domain name associated with the current user.

UserInteractive

Geçerli işlemin kullanıcı etkileşimli modunda çalışıp çalışmadığını gösteren bir değer alır.Gets a value indicating whether the current process is running in user interactive mode.

UserName

Geçerli iş parçacığıyla ilişkili kişinin Kullanıcı adını alır.Gets the user name of the person who is associated with the current thread.

Version

Ortak dil çalışma zamanının birincil, ikincil, derleme ve düzeltme numaralarını içeren bir sürümü alır.Gets a version consisting of the major, minor, build, and revision numbers of the common language runtime.

WorkingSet

İşlem bağlamına eşlenen fiziksel bellek miktarını alır.Gets the amount of physical memory mapped to the process context.

Yöntemler

Exit(Int32)

Bu işlemi sonlandırır ve işletim sistemine bir çıkış kodu döndürür.Terminates this process and returns an exit code to the operating system.

ExpandEnvironmentVariables(String)

Belirtilen dizeye gömülü her ortam değişkeninin adını, değişkenin değerinin dize eşdeğerini ile değiştirir, ardından sonuç dizeyi döndürür.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)

Windows uygulama olay günlüğü 'ne bir ileti yazdıktan sonra bir işlemi hemen sonlandırır ve ardından Microsoft 'a hata raporlama sırasında iletiyi içerir.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)

Windows uygulama olay günlüğü 'ne bir ileti yazdıktan sonra bir işlemi hemen sonlandırır ve ardından Microsoft 'a hata raporlamada ileti ve özel durum bilgilerini içerir.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()

Geçerli işlem için komut satırı bağımsız değişkenlerini içeren bir dize dizisi döndürür.Returns a string array containing the command-line arguments for the current process.

GetEnvironmentVariable(String)

Geçerli işlemden bir ortam değişkeninin değerini alır.Retrieves the value of an environment variable from the current process.

GetEnvironmentVariable(String, EnvironmentVariableTarget)

Geçerli işlemden veya geçerli kullanıcı veya yerel makine için Windows işletim sistemi kayıt defteri anahtarından bir ortam değişkeninin değerini alır.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()

Tüm ortam değişken adlarını ve değerlerini geçerli işlemden alır.Retrieves all environment variable names and their values from the current process.

GetEnvironmentVariables(EnvironmentVariableTarget)

Tüm ortam değişken adlarını ve bunların değerlerini geçerli işlemden veya geçerli kullanıcı veya yerel makine için Windows işletim sistemi kayıt defteri anahtarından alır.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)

Belirtilen numaralandırma tarafından tanımlanan sistem özel klasörünün yolunu alır.Gets the path to the system special folder that is identified by the specified enumeration.

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

Belirtilen numaralandırma tarafından tanımlanan sistem özel klasörünün yolunu alır ve özel klasörlere erişmek için belirtilen seçeneği kullanır.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()

Geçerli bilgisayardaki mantıksal sürücülerin adlarını içeren bir dize dizisi döndürür.Returns an array of string containing the names of the logical drives on the current computer.

SetEnvironmentVariable(String, String)

Geçerli işlemde depolanan bir ortam değişkenini oluşturur, değiştirir veya siler.Creates, modifies, or deletes an environment variable stored in the current process.

SetEnvironmentVariable(String, String, EnvironmentVariableTarget)

Geçerli işlemde veya geçerli kullanıcı veya yerel makine için ayrılmış Windows işletim sistemi kayıt defteri anahtarında depolanan bir ortam değişkenini oluşturur, değiştirir veya siler.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.

Şunlara uygulanır