A few weeks ago I started a new project called TSMBIOS, this is a library which allows access the SMBIOS using the Object Pascal language (Delphi or Free Pascal).
What is the SMBIOS?
SMBIOS stands for System Management BIOS , this standard is tightly related and developed by the DMTF (Desktop Management Task Force).
The SMBIOS contains a description of the system’s hardware components, the information stored in the SMBIOS typically includes system manufacturer, model name, serial numbers, BIOS version, asset tag, processors, ports, device memory installed and so on.
Note : The amount and accuracy of the SMBIOS information depends on the computer manufacturer.
Which are the advantages of use the SMBIOS?
- You can retrieve the information without having to probe for the actual hardware. this is a good point in terms of speed and safeness.
- The SMBIOS information is very well documented.
- You can avoid the use of undocumented functions to get hardware info (for example the RAM type and manufacturer).
- Useful for create a Hardware ID (machine fingerprint).
How it works?
The BIOS typically populates the SMBIOS structures at system boot time, and is not in control when the OS is running. Therefore, dynamically changing data is rarely represented in SMBIOS tables.
The SMBIOS Entry Point is located somewhere between the addresses 0xF0000 and 0xFFFFF, in early Windows systems (Win95, Win98) it was possible access this space address directly, but after with the introduction of the NT Systems and the new security changes the BIOS was accessible through section \Device\PhysicalMemory, but this last method was disabled as well in Windows Server 2003 Service Pack 1, and replaced with 2 new WinApi functions the EnumSystemFirmwareTables and GetSystemFirmwareTable, Additionally the WMI supports reading the entire contents of SMBIOS data i using the MSSMBios_RawSMBiosTables class inside of the root\wmi namespace.
Note : you can find more information about the SMBIOS Support in Windows on this link.
The TSMBIOS can be compiled using a WinApi mode (uses the GetSystemFirmwareTable function) or using the WMI Mode (uses the MSSMBios_RawSMBiosTables class)
If you uses the WinApi Mode you don’t need use COM and the final size of the Application will be smaller, but the WinAPI functions was introduced in Windows Vista and Windows XP x64 (So in Windows Xp x86 will fail). Otherwise using the WMI mode you will need use COM (CoInitialize and CoUninitialize), but also you will get two additional advantages 1) The WMI will work even in Windows Xp x86 systems, 2) You can read then SMBIOS data of local and remote computers.
In order to use the TSMBIOS in your application only you must add the uSMBIOS unit to your uses clause, then create a instance for the TSMBios class using the proper constructor
// Default constructor, used for populate the TSMBIOS class using the current mode selected (WMI or WinApi) constructor Create; overload; // Use this constructor to load the SMBIOS data from a previously saved file. constructor Create(const FileName : string); overload; {$IFDEF USEWMI} // Use this constructor to read the SMBIOS from a remote machine. constructor Create(const RemoteMachine, UserName, Password : string); overload; {$ENDIF}
and finally use the property which expose the SMBIOS info which you need. In this case as is show in the sample code the BatteryInformation property is used to get all the info of the batteries installed on the system.
{$APPTYPE CONSOLE} uses Classes, SysUtils, uSMBIOS in '..\..\Common\uSMBIOS.pas'; procedure GetBatteryInfo; Var SMBios : TSMBios; LBatteryInfo : TBatteryInformation; begin SMBios:=TSMBios.Create; try WriteLn('Battery Information'); WriteLn('-------------------'); if SMBios.HasBatteryInfo then for LBatteryInfo in SMBios.BatteryInformation do begin WriteLn('Location '+LBatteryInfo.GetLocationStr); WriteLn('Manufacturer '+LBatteryInfo.GetManufacturerStr); WriteLn('Manufacturer Date '+LBatteryInfo.GetManufacturerDateStr); WriteLn('Serial Number '+LBatteryInfo.GetSerialNumberStr); WriteLn('Device Name '+LBatteryInfo.GetDeviceNameStr); WriteLn('Device Chemistry '+LBatteryInfo.GetDeviceChemistry); WriteLn(Format('Design Capacity %d mWatt/hours',[LBatteryInfo.RAWBatteryInfo.DesignCapacity*LBatteryInfo.RAWBatteryInfo.DesignCapacityMultiplier])); WriteLn(Format('Design Voltage %d mVolts',[LBatteryInfo.RAWBatteryInfo.DesignVoltage])); WriteLn('SBDS Version Number '+LBatteryInfo.GetSBDSVersionNumberStr); WriteLn(Format('Maximum Error in Battery Data %d%%',[LBatteryInfo.RAWBatteryInfo.MaximumErrorInBatteryData])); WriteLn(Format('SBDS Version Number %.4x',[LBatteryInfo.RAWBatteryInfo.SBDSSerialNumber])); WriteLn('SBDS Manufacture Date '+LBatteryInfo.GetSBDSManufactureDateStr); WriteLn('SBDS Device Chemistry '+LBatteryInfo.GetSBDSDeviceChemistryStr); WriteLn(Format('OEM Specific %.8x',[LBatteryInfo.RAWBatteryInfo.OEM_Specific])); WriteLn; end else Writeln('No Battery Info was found'); finally SMBios.Free; end; end; begin try GetBatteryInfo; except on E:Exception do Writeln(E.Classname, ':', E.Message); end; Writeln('Press Enter to exit'); Readln; end.
TSMBIOS Features
- Source Full documented compatible with the help insight feature, available since Delphi 2005.
- Supports SMBIOS Version from 2.1 to 2.7.1
- Supports Delphi 5, 6, 7, 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3, XE4.
- Compatible with FPC 2.6.0 (Windows and Linux)
- SMBIOS Data can be obtained using WinApi, WMI or loading a saved SMBIOS dump
- SMBIOS Data can be saved and load to a file
- SMBIOS Data can be obtained from remote machines
SMBIOS Tables supported
- BIOS Information (Type 0)
- System Information (Type 1)
- Baseboard (or Module) Information (Type 2)
- System Enclosure or Chassis (Type 3)
- Processor Information (Type 4)
- Cache Information (Type 7)
- Port Connector Information (Type 8)
- System Slots (Type 9)
- OEM Strings (Type 11)
- System Configuration Options (Type 12)
- BIOS Language Information (Type 13)
- Physical Memory Array (Type 16)
- Memory Device (Type 17)
- Memory Array Mapped Address (Type 19)
- Memory Device Mapped Address (Type 20)
- Built-in Pointing Device (Type 21)
- Portable Battery (Type 22)
- Voltage Probe (Type 26)
- Cooling Device (Type 27)
- Temperature Probe (Type 28)
- Electrical Current Probe (Type 29)
Pingback: Reading the SMBios Tables using Delphi « The Road to Delphi – a Blog about programming
March 20, 2013 at 1:31 am
The documentation states that it supports SMBIOS Version from 2.1 to 2.7.1. However, the code raises an exception saying it doesn’t support anything less than 2.4. Is this a mistake? Because this means that I cant run this on relatively new computer, which would make this class useless.
March 20, 2013 at 9:42 am
Hi Chris, thanks for your feedback, Yes this is a mistakle, that restriction was now removed, in the future please report this kind of errors in the issue page of the project http://code.google.com/p/tsmbios/issues/list
April 13, 2013 at 6:42 pm
Hi,
I get this error when use unit uSMBIOS.
—————————
Project project.exe raised exception class EIntfCastError with message ‘Interface not supported’.
—————————
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumvariant;
Please help me.
Thank you.
Windows xp sp3 – Rad studio xe2
April 14, 2013 at 1:05 pm
Please report this issue using the issue page of the project http://code.google.com/p/tsmbios/issues/list
March 18, 2014 at 5:02 pm
Hi.
From time to time, I have error, when I use uSMBIOS
“… EOleException with message ‘Invalid query’.
in uSMBIOS unit in line
5184: FWbemObjectSet := FWMIService.ExecQuery(‘SELECT * FROM MSSmBios_RawSMBiosTables’, ‘WQL’, wbemFlagForwardOnly);
Can You help me?
Thank You.
Windows 7 Ultimate x64 SP1, Delphi 2007.
March 18, 2014 at 5:53 pm
Please use the issue page of the project to report this.
January 10, 2015 at 8:57 pm
Thanks, useful routines.
February 16, 2016 at 6:37 pm
Hi Rodrigo….do you know if it’s possible using Lazarus\FPC to get a handle on and read from \\?\PhysicalMemory in the same way that closed software tools like DumpIt (http://www.moonsols.com/products/) and Belkasofts RAM Capturer (https://belkasoft.com/ram-capturer) do?
February 24, 2016 at 2:30 pm
Hi, I’m not familiarized with the tools which you listed, but in order to access the RAM content in a safe manner you would have to write a kernel mode driver. For do that in FPC you can try the Target NativeNT. But I don’t know if will support all the Kernel Mode Driver Framework features. For this kind of tasks I usually use C.
March 7, 2016 at 5:13 am
Under which license is the code distributed? It seems that there is no license file in the repository or on this page…
March 8, 2016 at 3:25 pm
The license (MPL 1.1) appears in the header of the uSMBios unit.