본문 바로가기

C# Winform

C# Winform | Hardware Info | CPU ID, HDD, Mac, Serial

by C기억저장소 2020. 4. 29.

C# Winform | Hardware Info | CPU ID, HDD, Mac, Serial

 

  using System.Management

 

 

 

 

  MSDN

 

MSDN

 

Computer System Hardware Classes - Win32 apps

Computer System Hardware Classes In this article --> The Computer System Hardware category groups classes together that represent hardware related objects. Examples include input devices, hard disks, expansion cards, video devices, networking devices, and

docs.microsoft.com

 

MSDN - Classe Name

 

 

MSDN - Win32_DiskDrive Syntax

 

위 이미지 예제 처럼 MSDN을 참고하여 ClassName과 Syntax를 함수 인자에 넣으면 원하는 하드웨어 정보를 얻을 수 있다.

 

 

  TEST CODE

 

private void button1_Click(object sender, EventArgs e)
{
    GetHardwareInfo("Win32_Processor""Name");
    GetHardwareInfo("Win32_Processor""ProcessorID");
    GetHardwareInfo("Win32_SystemBIOS""PartComponent");
    GetHardwareInfo("Win32_NetworkAdapter""MACAddress");
    GetHardwareInfo("Win32_DiskDrive""SerialNumber");
}
 
private void GetHardwareInfo(string classname, string syntax)
{
    ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from " + classname);
    foreach (ManagementObject Source in mos.Get())
    {
        Console.WriteLine(syntax + " - " + Source[syntax]);
    }
}
cs

 

  output