Fixed Issue 69.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.Management;
43 namespace OpenHardwareMonitor.Hardware.Mainboard {
47 private Structure[] table;
49 private BIOSInformation biosInformation = null;
50 private BaseBoardInformation baseBoardInformation = null;
53 int p = (int)System.Environment.OSVersion.Platform;
54 if ((p == 4) || (p == 128))
57 List<Structure> structureList = new List<Structure>();
61 ManagementObjectCollection collection = new ManagementObjectSearcher(
62 "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
64 foreach (ManagementObject mo in collection) {
65 raw = (byte[])mo["SMBiosData"];
70 if (raw != null && raw.Length > 0) {
72 byte type = raw[offset];
73 while (offset + 4 < raw.Length && type != 127) {
76 int length = raw[offset + 1];
77 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
79 if (offset + length > raw.Length)
81 byte[] data = new byte[length];
82 Array.Copy(raw, offset, data, 0, length);
85 List<string> stringsList = new List<string>();
86 if (offset < raw.Length && raw[offset] == 0)
89 while (offset < raw.Length && raw[offset] != 0) {
90 StringBuilder sb = new StringBuilder();
91 while (offset < raw.Length && raw[offset] != 0) {
92 sb.Append((char)raw[offset]); offset++;
95 stringsList.Add(sb.ToString());
100 this.biosInformation = new BIOSInformation(
101 type, handle, data, stringsList.ToArray());
102 structureList.Add(this.biosInformation); break;
103 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
104 type, handle, data, stringsList.ToArray());
105 structureList.Add(this.baseBoardInformation); break;
106 default: structureList.Add(new Structure(
107 type, handle, data, stringsList.ToArray())); break;
112 table = structureList.ToArray();
115 public string GetReport() {
116 StringBuilder r = new StringBuilder();
118 if (biosInformation != null) {
119 r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
120 r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
124 if (baseBoardInformation != null) {
125 r.Append("Mainboard Manufacturer: ");
126 r.AppendLine(baseBoardInformation.ManufacturerName);
127 r.Append("Mainboard Name: ");
128 r.AppendLine(baseBoardInformation.ProductName);
135 public BIOSInformation BIOS {
136 get { return biosInformation; }
139 public BaseBoardInformation Board {
140 get { return baseBoardInformation; }
143 public class Structure {
145 private ushort handle;
148 private string[] strings;
150 protected string GetString(int offset) {
151 if (offset < data.Length && data[offset] > 0 &&
152 data[offset] <= strings.Length)
153 return strings[data[offset] - 1];
158 public Structure(byte type, ushort handle, byte[] data, string[] strings)
161 this.handle = handle;
163 this.strings = strings;
166 public byte Type { get { return type; } }
168 public ushort Handle { get { return handle; } }
171 public class BIOSInformation : Structure {
173 private string vendor;
174 private string version;
176 public BIOSInformation(byte type, ushort handle, byte[] data,
178 : base(type, handle, data, strings) {
180 this.vendor = GetString(0x04);
181 this.version = GetString(0x05);
184 public string Vendor { get { return vendor; } }
186 public string Version { get { return version; } }
189 public class BaseBoardInformation : Structure {
191 private string manufacturerName;
192 private string productName;
193 private string version;
194 private string serialNumber;
195 private Manufacturer manufacturer;
198 public BaseBoardInformation(byte type, ushort handle, byte[] data,
200 : base(type, handle, data, strings) {
202 this.manufacturerName = GetString(0x04).Trim();
203 this.productName = GetString(0x05).Trim();
204 this.version = GetString(0x06).Trim();
205 this.serialNumber = GetString(0x07).Trim();
207 switch (manufacturerName) {
208 case "ASUSTeK Computer INC.":
209 manufacturer = Manufacturer.ASUS; break;
212 manufacturer = Manufacturer.DFI; break;
213 case "EPoX COMPUTER CO., LTD":
214 manufacturer = Manufacturer.EPoX; break;
216 manufacturer = Manufacturer.EVGA; break;
217 case "Gigabyte Technology Co., Ltd.":
218 manufacturer = Manufacturer.Gigabyte; break;
220 manufacturer = Manufacturer.IBM; break;
221 case "MICRO-STAR INTERNATIONAL CO., LTD":
222 case "MICRO-STAR INTERNATIONAL CO.,LTD":
223 manufacturer = Manufacturer.MSI; break;
225 manufacturer = Manufacturer.Unknown; break;
228 switch (productName) {
229 case "Crosshair III Formula":
230 model = Model.Crosshair_III_Formula; break;
231 case "M2N-SLI DELUXE":
232 model = Model.M2N_SLI_DELUXE; break;
233 case "P5W DH Deluxe":
234 model = Model.P5W_DH_Deluxe; break;
235 case "LP BI P45-T2RS Elite":
236 model = Model.LP_BI_P45_T2RS_Elite; break;
237 case "LP DK P55-T3eH9":
238 model = Model.LP_DK_P55_T3eH9; break;
239 case "X58 SLI Classified":
240 model = Model.X58_SLI_Classified; break;
242 model = Model._965P_S3; break;
244 model = Model.EP45_DS3R; break;
246 model = Model.EP45_UD3R; break;
248 model = Model.EX58_EXTREME; break;
249 case "GA-MA785GMT-UD2H":
250 model = Model.GA_MA785GMT_UD2H; break;
252 model = Model.P35_DS3; break;
254 model = Model.P35_DS3L; break;
256 model = Model.X38_DS5; break;
258 model = Model.Unknown; break;
262 public string ManufacturerName { get { return manufacturerName; } }
264 public string ProductName { get { return productName; } }
266 public string Version { get { return version; } }
268 public string SerialNumber { get { return serialNumber; } }
270 public Manufacturer Manufacturer { get { return manufacturer; } }
272 public Model Model { get { return model; } }