[C#.NET]여러가지 머신레벨의 시스템 정보 얻는 방법

2023. 2. 5. 19:07프로그래밍

728x90

 

 

How to find various machine-level system information with C# .NET

The Environment class holds a range of properties that help you describe the system your app is running on. Here come some examples with inline comments: View all posts related to diagnostics here.

dotnetcodr.com

 

Environment 클래스에는 앱이 실행되는 시스템을 설명하는 데 도움이 되는 다양한 속성이 있습니다. 

다음은 인라인 주석이 있는 몇 가지 예입니다.

 

  • 내 PC는 64비트 OS이므로 true를 반환합니다.
  • 컴퓨터 이름을 반환합니다. 제 경우에는 ANDRAS1입니다.
  • 운영 체제 버전, 빌드, 메이저, 마이너 등에 대한 정보를 반환합니다.
  • 플랫폼 ID를 열거형으로 반환합니다. 제 경우에는 Win32NT입니다.
  • 현재 설치된 서비스 팩, 내 경우에는 서비스 팩 1
  • OS의 toString 버전, 이 PC의 "Microsoft Windows NT 6.1.7601 서비스 팩 1"입니다.
  • 이 PC에는 4개의 프로세서가 있습니다.
  • 2개의 논리 드라이브 반환: C: 및 D:
  • 이것은 시스템의 모든 환경 변수를 찾고 이를 통해 반복하는 방법입니다.
  • 현재 CLR 버전을 검색합니다. 제 경우에는 "4.0.30319.18444"입니다.
//returns true on my PC as it is a 64-bit OS
bool is64BitOperatingSystem = Environment.Is64BitOperatingSystem;
//returns the machine name, in my case ANDRAS1
string machineName = Environment.MachineName;
             
//returns information about the operating system version, build, major, minor etc.
OperatingSystem os = Environment.OSVersion;
//returns the platform id as an enumeration, in my case it's Win32NT
PlatformID platform = os.Platform;          
//the currently installed service pack, Service Pack 1 in my case
string servicePack = os.ServicePack;
//the toString version of the OS, this is "Microsoft Windows NT 6.1.7601 Service Pack 1" on this PC
string version = os.VersionString;
 
//I have 4 processors on this PC
int processorCount = Environment.ProcessorCount;
 
//returns 2 logical drives: C: and D:
string[] logicalDrives = Environment.GetLogicalDrives();
 
//this is how to find all environmental variables of the system and iterate through them
IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (string key in envVars.Keys)
{
    //e.g. the JAVA_HOME env.var is set to "C:\Progra~1\Java\jdk1.7.0_51\"
    Debug.WriteLine(string.Concat("key: ", key, ": ", envVars[key]));
}
 
//retrieve the current CLR version, in my case it's "4.0.30319.18444"
Version clrVersion = Environment.Version;
 

 

 

728x90