Environment 클래스
현재 환경 및 플랫폼에 대한 정보 및 조작 방법을 제공합니다. 이 클래스는 상속될 수 없습니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
Public NotInheritable Class Environment
‘사용 방법
정적 클래스의 멤버는 클래스 인스턴스를 사용하지 않고 직접 액세스할 수 있습니다.
[ComVisibleAttribute(true)]
public static class Environment
[ComVisibleAttribute(true)]
public ref class Environment abstract sealed
/** @attribute ComVisibleAttribute(true) */
public final class Environment
ComVisibleAttribute(true)
public final class Environment
설명
Environment 클래스를 사용하여 명령줄 인수, 종료 코드, 환경 변수 설정, 호출 스택의 내용, 마지막으로 시스템을 부팅한 이후 경과된 시간, 공용 언어 런타임 버전 등의 정보를 검색합니다.
예제
' 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:\
'
// 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
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
import System.*;
import System.Collections.*;
class Sample
{
public static void main(String[] args)
{
String str;
String nl = Environment.get_NewLine();
//
Console.WriteLine();
Console.WriteLine("-- Environment members --");
// Invoke this sample with an arbitrary set of command line arguments.
Console.WriteLine("CommandLine: {0}", Environment.get_CommandLine());
String arguments[] = Environment.GetCommandLineArgs();
Console.WriteLine("GetCommandLineArgs: {0}",
String.Join(", ", arguments));
// <-- Keep this information secure! -->
Console.WriteLine("CurrentDirectory: {0}",
Environment.get_CurrentDirectory());
Console.WriteLine("ExitCode: {0}", (Int32)Environment.get_ExitCode());
Console.WriteLine("HasShutdownStarted: {0}",
(System.Boolean)Environment.get_HasShutdownStarted());
// <-- Keep this information secure! -->
Console.WriteLine("MachineName: {0}", Environment.get_MachineName());
Console.WriteLine("NewLine: {0} first line{0} second line{0} "
+ "third line", Environment.get_NewLine());
Console.WriteLine("OSVersion: {0}", Environment.get_OSVersion().
ToString());
Console.WriteLine("StackTrace: '{0}'", Environment.get_StackTrace());
// <-- Keep this information secure! -->
Console.WriteLine("SystemDirectory: {0}", Environment.
get_SystemDirectory());
Console.WriteLine("TickCount: {0}", (Int32)Environment.
get_TickCount());
// <-- Keep this information secure! -->
Console.WriteLine("UserDomainName: {0}",
Environment.get_UserDomainName());
Console.WriteLine("UserInteractive: {0}",
(System.Boolean)Environment.get_UserInteractive());
// <-- Keep this information secure! -->
Console.WriteLine("UserName: {0}", Environment.get_UserName());
Console.WriteLine("Version: {0}", Environment.get_Version().
ToString());
Console.WriteLine("WorkingSet: {0}",
System.Convert.ToString(Environment.get_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();
DictionaryEntry de;
IEnumerator enumObj = environmentVariables.GetEnumerator();
while (enumObj.MoveNext()) {
de = (DictionaryEntry)enumObj.get_Current();
Console.WriteLine(" {0} = {1}", de.get_Key(), de.get_Value());
}
Console.WriteLine("GetFolderPath: {0}",
Environment.GetFolderPath(Environment.SpecialFolder.System));
String drives[] = Environment.GetLogicalDrives();
Console.WriteLine("GetLogicalDrives: {0}",
String.Join(", ", drives));
} //main
} //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:\
*/
상속 계층 구조
System.Object
System.Environment
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원