첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

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
    }
}

 

728x90

 

▶ 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
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요