728x90
300x250
[C#] 하드웨어 정보 가져오기 - 구현 방법

 

C#으로 하드웨어 정보 가져오기에 대한 구현 방법을 소개하고자 합니다.

 


1. 참조 라이브러리


솔루션 -> 참조 -> Microsoft.VisualBasic

 


2. 구현


using System.Management;

 

private void Form2_Load(object sender, EventArgs e)
{
            int i;

            /// 배치 장소
            c_area.Items.Add("본사");
            c_area.Items.Add("영업지사");
            c_area.Items.Add("개발");


            /// 배치 부서
            c_department.Items.Add("사무실");
            c_department.Items.Add("생산");
            c_department.Items.Add("설계");
            c_department.Items.Add("출하");
            c_department.Items.Add("회의실");
            c_department.Items.Add("사장실");


            /// 자산 구분
            c_asset.Items.Add("소유");
            c_asset.Items.Add("임대");


            /// 자산 형태
            c_type.Items.Add("데스크탑");
            c_type.Items.Add("노트북");
            c_type.Items.Add("넷북");
            c_type.Items.Add("타블렛노트");
           
            // 전산장비 정보 가져오기

            // 1. CPU 정보 가져오기
            ManagementObjectSearcher MS2 = new ManagementObjectSearcher("Select * from Win32_Processor");
            foreach (ManagementObject MO in MS2.Get())
            {
                c_CPU.Text = MO["Name"].ToString();
            }
            // 2. RAM 정보 가져오기
            ulong a = new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024 / 1024;
            string b = a.ToString() + "MB";
            c_RAM.Text = b;
            // 3. M/B 정보 가져오기
            MS2 = new ManagementObjectSearcher("Select * from Win32_BaseBoard");
            foreach (ManagementObject MO in MS2.Get())
            {
                c_MB.Text = MO["Product"].ToString();
            }
            // 4. VGA 정보 가져오기
            MS2 = new ManagementObjectSearcher("Select * from Win32_DisplayConfiguration");
            foreach (ManagementObject MO in MS2.Get())
            {
                c_VGA.Text = MO["Description"].ToString();
            }
            // 5. HDD 정보 가져오기

            List<HardDrive> hdCollection = new List<HardDrive>();
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

            foreach (ManagementObject wmi_HD in searcher.Get())
            { 
               HardDrive hd = new HardDrive();
               hd.Model = wmi_HD["Model"].ToString();
               hd.Type = wmi_HD["InterfaceType"].ToString();
               hdCollection.Add(hd);
            }
            searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
            int ii = 0;
            foreach (ManagementObject wmi_HD in searcher.Get())
            {
                if (ii >= hdCollection.Count)
                {
                    break;
                }
           
                HardDrive hd = (HardDrive)hdCollection[ii];
                // get the hardware serial no.

                if (wmi_HD["SerialNumber"] == null)
                    hd.SerialNo = "None";
                else
                    hd.SerialNo = wmi_HD["SerialNumber"].ToString().Trim();

                ++ii;
            }

            c_HDD_1.Text = hdCollection[0].Model.ToString();
            c_HDD_Type_1.Text = hdCollection[0].Type.ToString();
            if (hdCollection.Count < 1)
            {
                c_HDD_2.Text = hdCollection[1].Model.ToString();
                c_HDD_Type_2.Text = hdCollection[1].Type.ToString();
            }
        }

       

 

// 하드 정보담는 공간
        public class HardDrive
        {
            private string model = null;
            private string type = null;
            private string serialNo = null;
            public string Model
            {
                get { return model; }
                set { model = value; }
            }
            public string Type
            {
                get { return type; }
                set { type = value; }
            }
            public string SerialNo
            {
                get { return serialNo; }
                set { serialNo = value; }
            }
        }

 

 


3. 참고자료(Reference)


1. http://anothermsdn.com/?paged=13, Accessed by 2013-08-04

=> 현재 웹사이트 폐쇠됨.

 

반응형

+ Recent posts