■ WMI를 사용해 운영 체제 정보를 구하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
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 //////////////////////////////////////////////////////////////////////////////////////////////////// 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) { ManagementObjectSearcher mso = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"); foreach(ManagementObject mo in mso.Get()) { AddListViewData(mo, "BootDevice" ); AddListViewData(mo, "BuildNumber" ); AddListViewData(mo, "BuildType" ); AddListViewData(mo, "Caption" ); AddListViewData(mo, "CodeSet" ); AddListViewData(mo, "CountryCode" ); AddListViewData(mo, "CreationClassName" ); AddListViewData(mo, "CSCreationClassName" ); AddListViewData(mo, "CSDVersion" ); AddListViewData(mo, "CSName" ); AddListViewData(mo, "CurrentTimeZone" ); AddListViewData(mo, "DataExecutionPrevention_Available" ); AddListViewData(mo, "DataExecutionPrevention_32BitApplications"); AddListViewData(mo, "DataExecutionPrevention_Drivers" ); AddListViewData(mo, "DataExecutionPrevention_SupportPolicy" ); AddListViewData(mo, "Debug" ); AddListViewData(mo, "Description" ); AddListViewData(mo, "Distributed" ); AddListViewData(mo, "EncryptionLevel" ); AddListViewData(mo, "ForegroundApplicationBoost" ); AddListViewData(mo, "FreePhysicalMemory" ); AddListViewData(mo, "FreeSpaceInPagingFiles" ); AddListViewData(mo, "FreeVirtualMemory" ); AddListViewData(mo, "InstallDate" ); AddListViewData(mo, "LargeSystemCache" ); AddListViewData(mo, "LastBootUpTime" ); AddListViewData(mo, "LocalDateTime" ); AddListViewData(mo, "Locale" ); AddListViewData(mo, "Manufacturer" ); AddListViewData(mo, "MaxNumberOfProcesses" ); AddListViewData(mo, "MaxProcessMemorySize" ); AddListViewData(mo, "MUILanguages[]" ); AddListViewData(mo, "Name" ); AddListViewData(mo, "NumberOfLicensedUsers" ); AddListViewData(mo, "NumberOfProcesses" ); AddListViewData(mo, "NumberOfUsers" ); AddListViewData(mo, "OperatingSystemSKU" ); AddListViewData(mo, "Organization" ); AddListViewData(mo, "OSArchitecture" ); AddListViewData(mo, "OSLanguage" ); AddListViewData(mo, "OSProductSuite" ); AddListViewData(mo, "OSType" ); AddListViewData(mo, "OtherTypeDescription" ); AddListViewData(mo, "PAEEnabled" ); AddListViewData(mo, "PlusProductID" ); AddListViewData(mo, "PlusVersionNumber" ); AddListViewData(mo, "Primary" ); AddListViewData(mo, "ProductType" ); AddListViewData(mo, "QuantumLength" ); AddListViewData(mo, "QuantumType" ); AddListViewData(mo, "RegisteredUser" ); AddListViewData(mo, "SerialNumber" ); AddListViewData(mo, "ServicePackMajorVersion" ); AddListViewData(mo, "ServicePackMinorVersion" ); AddListViewData(mo, "SizeStoredInPagingFiles" ); AddListViewData(mo, "Status" ); AddListViewData(mo, "SuiteMask" ); AddListViewData(mo, "SystemDevice" ); AddListViewData(mo, "SystemDirectory" ); AddListViewData(mo, "SystemDrive" ); AddListViewData(mo, "TotalSwapSpaceSize" ); AddListViewData(mo, "TotalVirtualMemorySize" ); AddListViewData(mo, "TotalVisibleMemorySize" ); AddListViewData(mo, "Version" ); AddListViewData(mo, "WindowsDirectory" ); } foreach(ColumnHeader header in this.listView.Columns) { header.Width = -2; } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 리스트 뷰 데이터 추가하기 - AddListViewData(mo, propertyName) /// <summary> /// 리스트 뷰 데이터 추가하기 /// </summary> /// <param name="mo">관리 객체</param> /// <param name="propertyName">속성명</param> private void AddListViewData(ManagementObject mo, string propertyName) { string value; try { value = mo[propertyName].ToString(); } catch(Exception exception) { value = "[에러] : " + exception.Message; } this.listView.Items.Add(propertyName).SubItems.Add(value); } #endregion } } |