Jump to content
Vlachs

[Delphi] Access The System Management BIOS

Recommended Posts

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). [h=2]What is the SMBIOS?[/h] 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.

[h=2]Which are the advantages of use the SMBIOS?[/h]

  • 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).

[h=2]How it works?[/h] 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

[TABLE]

[TR]

[TD=class: number]1[/TD]

[TD=class: content]// Default constructor, used for populate the TSMBIOS class using the current mode selected (WMI or WinApi)[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]2[/TD]

[TD=class: content]constructor Create; overload;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]3[/TD]

[TD=class: content]// Use this constructor to load the SMBIOS data from a previously saved file.[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]4[/TD]

[TD=class: content]constructor Create(const FileName : string); overload;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]5[/TD]

[TD=class: content]{$IFDEF USEWMI}[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]6[/TD]

[TD=class: content]// Use this constructor to read the SMBIOS from a remote machine.[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]7[/TD]

[TD=class: content]constructor Create(const RemoteMachine, UserName, Password : string); overload;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]8[/TD]

[TD=class: content]{$ENDIF}[/TD]

[/TR]

[/TABLE]

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.

[TABLE]

[TR]

[TD=class: number]01[/TD]

[TD=class: content]{$APPTYPE CONSOLE}[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]02[/TD]

[TD=class: content] [/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]03[/TD]

[TD=class: content]uses[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]04[/TD]

[TD=class: content] Classes,[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]05[/TD]

[TD=class: content] SysUtils,[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]06[/TD]

[TD=class: content] uSMBIOS in '..\..\Common\uSMBIOS.pas';[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]07[/TD]

[TD=class: content] [/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]08[/TD]

[TD=class: content]procedure GetBatteryInfo;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]09[/TD]

[TD=class: content]Var[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]10[/TD]

[TD=class: content] SMBios : TSMBios;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]11[/TD]

[TD=class: content] LBatteryInfo : TBatteryInformation;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]12[/TD]

[TD=class: content]begin[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]13[/TD]

[TD=class: content] SMBios:=TSMBios.Create;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]14[/TD]

[TD=class: content] try[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]15[/TD]

[TD=class: content] WriteLn('Battery Information');[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]16[/TD]

[TD=class: content] WriteLn('-------------------');[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]17[/TD]

[TD=class: content] if SMBios.HasBatteryInfo then[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]18[/TD]

[TD=class: content] for LBatteryInfo in SMBios.BatteryInformation do[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]19[/TD]

[TD=class: content] begin[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]20[/TD]

[TD=class: content] WriteLn('Location '+LBatteryInfo.GetLocationStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]21[/TD]

[TD=class: content] WriteLn('Manufacturer '+LBatteryInfo.GetManufacturerStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]22[/TD]

[TD=class: content] WriteLn('Manufacturer Date '+LBatteryInfo.GetManufacturerDateStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]23[/TD]

[TD=class: content] WriteLn('Serial Number '+LBatteryInfo.GetSerialNumberStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]24[/TD]

[TD=class: content] WriteLn('Device Name '+LBatteryInfo.GetDeviceNameStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]25[/TD]

[TD=class: content] WriteLn('Device Chemistry '+LBatteryInfo.GetDeviceChemistry);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]26[/TD]

[TD=class: content] WriteLn(Format('Design Capacity %d mWatt/hours',[LBatteryInfo.RAWBatteryInfo.DesignCapacity*LBatteryInfo.RAWBatteryInfo.DesignCapacityMultiplier]));[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]27[/TD]

[TD=class: content] WriteLn(Format('Design Voltage %d mVolts',[LBatteryInfo.RAWBatteryInfo.DesignVoltage]));[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]28[/TD]

[TD=class: content] WriteLn('SBDS Version Number '+LBatteryInfo.GetSBDSVersionNumberStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]29[/TD]

[TD=class: content] WriteLn(Format('Maximum Error in Battery Data %d%%',[LBatteryInfo.RAWBatteryInfo.MaximumErrorInBatteryData]));[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]30[/TD]

[TD=class: content] WriteLn(Format('SBDS Version Number %.4x',[LBatteryInfo.RAWBatteryInfo.SBDSSerialNumber]));[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]31[/TD]

[TD=class: content] WriteLn('SBDS Manufacture Date '+LBatteryInfo.GetSBDSManufactureDateStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]32[/TD]

[TD=class: content] WriteLn('SBDS Device Chemistry '+LBatteryInfo.GetSBDSDeviceChemistryStr);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]33[/TD]

[TD=class: content] WriteLn(Format('OEM Specific %.8x',[LBatteryInfo.RAWBatteryInfo.OEM_Specific]));[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]34[/TD]

[TD=class: content] WriteLn;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]35[/TD]

[TD=class: content] end[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]36[/TD]

[TD=class: content] else[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]37[/TD]

[TD=class: content] Writeln('No Battery Info was found');[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]38[/TD]

[TD=class: content] finally[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]39[/TD]

[TD=class: content] SMBios.Free;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]40[/TD]

[TD=class: content] end;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]41[/TD]

[TD=class: content]end;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]42[/TD]

[TD=class: content] [/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]43[/TD]

[TD=class: content]begin[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]44[/TD]

[TD=class: content] try[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]45[/TD]

[TD=class: content] GetBatteryInfo;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]46[/TD]

[TD=class: content] except[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]47[/TD]

[TD=class: content] on E:Exception do[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]48[/TD]

[TD=class: content] Writeln(E.Classname, ':', E.Message);[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]49[/TD]

[TD=class: content] end;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]50[/TD]

[TD=class: content] Writeln('Press Enter to exit');[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]51[/TD]

[TD=class: content] Readln;[/TD]

[/TR]

[/TABLE]

[TABLE]

[TR]

[TD=class: number]52[/TD]

[TD=class: content]end.[/TD]

[/TR]

[/TABLE]

[h=2]TSMBIOS Features[/h]

  • 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 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3.
  • Compatible with FPC 2.6.0 (Windows Only)
  • 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

[h=3]SMBIOS Tables supported[/h]

[h=3]The TSMBIOS is a Open Source project is hosted in the code google site.[/h]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...