Fixed Issue 63.
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;
215 case "Gigabyte Technology Co., Ltd.":
216 manufacturer = Manufacturer.Gigabyte; break;
218 manufacturer = Manufacturer.IBM; break;
219 case "MICRO-STAR INTERNATIONAL CO., LTD":
220 case "MICRO-STAR INTERNATIONAL CO.,LTD":
221 manufacturer = Manufacturer.MSI; break;
223 manufacturer = Manufacturer.Unknown; break;
226 switch (productName) {
227 case "P5W DH Deluxe":
228 model = Model.P5W_DH_Deluxe; break;
229 case "LP BI P45-T2RS Elite":
230 model = Model.LP_BI_P45_T2RS_Elite; break;
231 case "LP DK P55-T3eH9":
232 model = Model.LP_DK_P55_T3eH9; break;
234 model = Model._965P_S3; break;
236 model = Model.EP45_DS3R; break;
238 model = Model.EP45_UD3R; break;
239 case "GA-MA785GMT-UD2H":
240 model = Model.GA_MA785GMT_UD2H; break;
242 model = Model.P35_DS3; break;
244 model = Model.X38_DS5; break;
246 model = Model.Unknown; break;
250 public string ManufacturerName { get { return manufacturerName; } }
252 public string ProductName { get { return productName; } }
254 public string Version { get { return version; } }
256 public string SerialNumber { get { return serialNumber; } }
258 public Manufacturer Manufacturer { get { return manufacturer; } }
260 public Model Model { get { return model; } }