unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ActiveX, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
public
end;
const
Win32_BIOS_Property : array[0..26] of string =
(
'BiosCharacteristics', 'BIOSVersion', 'BuildNumber',
'Caption', 'CodeSet', 'CurrentLanguage',
'Description', 'IdentificationCode', 'InstallableLanguages',
'InstallDate', 'LanguageEdition', 'ListOfLanguages',
'Manufacturer', 'Name', 'OtherTargetOS',
'PrimaryBIOS', 'ReleaseDate', 'SerialNumber',
'SMBIOSBIOSVersion', 'SMBIOSMajorVersion', 'SMBIOSMinorVersion',
'SMBIOSPresent', 'SoftwareElementID', 'SoftwareElementState',
'Status', 'TargetOperatingSystem', 'Version');
var
Form1: TForm1;
WMINameSpace : String;
WMIClass : String;
WMIProperty : String;
implementation
{$R *.dfm}
function GetWMIInfo(const WMINameSpace, WMIClass, WMIProperty : String) : Variant;
const
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet : OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
Value : LongWord;
SQLWMI : String;
WMIValue : Variant;
i : Integer;
begin
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
try
FWMIService := FSWbemLocator.ConnectServer('localhost', WMINameSpace, '', '');
except
raise Exception.Create('Error en WMI : NameSpace No Valido');
end;
SQLWMI := 'SELECT * FROM ' + WMIClass;
try
FWbemObjectSet := FWMIService.ExecQuery(SQLWMI,'WQL',wbemFlagForwardOnly);
except
raise Exception.Create('Error en WMI : Clase No Valida');
end;
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
if oEnum.Next(1, FWbemObject, Value) = 0 then
begin
try
WMIValue := FWbemObject.Properties_.Item(WMIProperty).Value;
except
raise Exception.Create('Error en WMI : Propiedad No Valida');
end;
if VarIsArray(WMIValue) then
begin
for i:= VarArrayLowBound(WMIValue,1) to VarArrayHighBound(WMIValue,1) do
Result := Result + ' ' + String(WMIValue[i]);
end
else if not VarIsNull(WMIValue) then
Result := WMIValue
else
Result := EmptyStr;
FWbemObject:=Unassigned;
end
else
raise Exception.Create('Elemento no Encontrado en WMI');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
WMIClass := 'Win32_BIOS';
WMINameSpace := 'root\CIMV2';
ListBox1.Clear;
for i := 0 to High(Win32_BIOS_Property) do
begin
WMIProperty := Format('%s = %s',[Win32_BIOS_Property[i],GetWMIInfo(WMINameSpace, WMIClass,Win32_BIOS_Property[i])]);
ListBox1.Items.Add(WMIProperty);
if ListBox1.ScrollWidth < ListBox1.Canvas.TextWidth(WMIProperty) then
ListBox1.ScrollWidth := ListBox1.Canvas.TextWidth(WMIProperty) + 120;
end;
end;
end.