■ WMI를 사용해 운영 체제 정보 구하기

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


TestProject.zip


MainForm.cs

 

 

using System;

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

 

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

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

 

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

 

        /// <summary>

        /// 폼 로드시 처리하기

        /// </summary>

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

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

        private void Form_Load(object sender, EventArgs e)

        {

            string osQuery = "SELECT * FROM Win32_OperatingSystem";

 

            ManagementObjectSearcher osMSO = new ManagementObjectSearcher(osQuery);

 

            foreach(ManagementObject osMO in osMSO.Get())

            {

                this.captionLabel.Text = osMO.Properties["Caption"].Value.ToString().Trim();

 

                this.versionLabel.Text = "Version "                                                  +

                                         osMO.Properties["Version"].Value.ToString()                 +

                                         " SP "                                                      +

                                         osMO.Properties["ServicePackMajorVersion"].Value.ToString() +

                                         "."                                                         +

                                         osMO.Properties["ServicePackMinorVersion"].Value.ToString();

            }

 

            string cpuQuery = "SELECT * FROM Win32_ComputerSystem";

 

            ManagementObjectSearcher cpuMSO = new ManagementObjectSearcher(cpuQuery);

 

            foreach(ManagementObject cpuMO in cpuMSO.Get())

            {

                this.cpuLabel.Text = cpuMO.Properties["NumberOfLogicalProcessors"].Value.ToString() + " processors";

            }

 

            string processQuery = "SELECT * FROM Win32_Processor";

 

            ManagementObjectSearcher processorMSO = new ManagementObjectSearcher(processQuery);

 

            foreach(ManagementObject processMO in processorMSO.Get())

            {

                this.bitLabel.Text = processMO.Properties["AddressWidth"].Value.ToString() + "-bit";

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요