첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ ManagementClass 클래스 : 컴퓨터 타입 구하기

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


TestProject.zip


ComputerType.cs

 

 

namespace TestProject

{

    /// <summary>

    /// 컴퓨터 타입

    /// </summary>

    public enum ComputerType

    {

        /// <summary>

        /// Other

        /// </summary>

        Other = 1,

        

        /// <summary>

        /// Unknown

        /// </summary>

        Unknown,

        

        /// <summary>

        /// Desktop

        /// </summary>

        Desktop,

        

        /// <summary>

        /// LowProfileDesktop

        /// </summary>

        LowProfileDesktop,

        

        /// <summary>

        /// PizzaBox

        /// </summary>

        PizzaBox,

        

        /// <summary>

        /// MiniTower

        /// </summary>

        MiniTower,

        

        /// <summary>

        /// Tower

        /// </summary>

        Tower,

        

        /// <summary>

        /// Portable

        /// </summary>

        Portable,

        

        /// <summary>

        /// Laptop

        /// </summary>

        Laptop,

        

        /// <summary>

        /// Notebook

        /// </summary>

        Notebook,

        

        /// <summary>

        /// Handheld

        /// </summary>

        Handheld,

        

        /// <summary>

        /// DockingStation

        /// </summary>

        DockingStation,

        

        /// <summary>

        /// AllInOne

        /// </summary>

        AllInOne,

        

        /// <summary>

        /// SubNotebook

        /// </summary>

        SubNotebook,

        

        /// <summary>

        /// SpaceSaving

        /// </summary>

        SpaceSaving,

        

        /// <summary>

        /// LunchBox

        /// </summary>

        LunchBox,

        

        /// <summary>

        /// MainSystemChassis

        /// </summary>

        MainSystemChassis,

        

        /// <summary>

        /// ExpansionChassis

        /// </summary>

        ExpansionChassis,

        

        /// <summary>

        /// SubChassis

        /// </summary>

        SubChassis,

        

        /// <summary>

        /// BusExpansionChassis

        /// </summary>

        BusExpansionChassis,

        

        /// <summary>

        /// PeripheralChassis

        /// </summary>

        PeripheralChassis,

        

        /// <summary>

        /// StorageChassis

        /// </summary>

        StorageChassis,

        

        /// <summary>

        /// RackMountChassis

        /// </summary>

        RackMountChassis,

        

        /// <summary>

        /// SealedCasePC

        /// </summary>

        SealedCasePC

    }

}

 

 

Program.cs

 

 

using System;

using System.Management;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

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

        ////////////////////////////////////////////////////////////////////////////////////////// Static

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

 

        #region 프로그램 시작하기 - Main(argumentArray)

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        /// <param name="argumentArray">인자 배열</param>

        private static void Main(string[] argumentArray)

        {

            Console.Title = "ManagementClass 클래스 : 컴퓨터 타입 구하기";

 

            ComputerType computerType = GetComputerType();

 

            Console.WriteLine($"컴퓨터 타입 : {computerType}");

        }

 

        #endregion

 

        #region 컴퓨터 타입 구하기 - GetComputerType()

 

        /// <summary>

        /// 컴퓨터 타입 구하기

        /// </summary>

        /// <returns>컴퓨터 타입</returns>

        private static ComputerType GetComputerType()

        {

            try

            {

                ManagementClass managementClass = new ManagementClass("Win32_SystemEnclosure");

                

                foreach(ManagementObject managementObject in managementClass.GetInstances())

                {

                    foreach(int index in (ushort[])managementObject.GetPropertyValue("ChassisTypes"))

                    {

                        return (ComputerType)index;

                    }

                }

                

                return ComputerType.Unknown;

            }

            catch

            {

                return ComputerType.Unknown;

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker

댓글을 달아 주세요