■ 메인보드 시리얼 번호/CPU ID 구하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Collections.Generic;

using System.Management;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            #region 이벤트를 설정한다.

 

            Load += Form_Load;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

 

        /// <summary>

        /// 폼 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Form_Load(object sender, EventArgs e)

        {

            this.mainboardSerialNumberListBox.DataSource = GetMainBoardSerialNumberList();

            this.cpuIDListBox.DataSource                 = GetCPUIDList();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 메인보드 시리얼 번호 리스트 구하기 - GetMainBoardSerialNumberList()

 

        /// <summary>

        /// 메인보드 시리얼 번호 리스트 구하기

        /// </summary>

        /// <returns>메인보드 시리얼 번호 리스트</returns>

        private List<string> GetMainBoardSerialNumberList()

        {

            List<string> list = new List<string>();

 

            string query = "SELECT * FROM Win32_BaseBoard";

 

            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(query);

 

            foreach(ManagementObject managementObject in managementObjectSearcher.Get())

            {

                list.Add(managementObject.GetPropertyValue("SerialNumber").ToString());

            }

 

            return list;

        }

 

        #endregion

        #region CPU ID 리스트 구하기 - GetCPUIDList()

 

        /// <summary>

        /// CPU ID 리스트 구하기

        /// </summary>

        /// <returns>CPU ID 리스트</returns>

        private List<string> GetCPUIDList()

        {

            List<string> list = new List<string>();

 

            string query = "Select * FROM Win32_Processor";

 

            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(query);

 

            foreach(ManagementObject managementObject in managementObjectSearcher.Get())

            {

                list.Add(managementObject.GetPropertyValue("ProcessorId").ToString());

            }

 

            return list;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요