14-01-2019, 12:51 PM
uses
ActiveX,
ComObj;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
function GetWMIstring(const WMIClass, WMIProperty:string): string;
const
wbemFlagForwardOnly = $00000020;
var
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
Result:='';
FWbemObjectSet:= FWMIService.ExecQuery(Format('Select %s from %s',[WMIProperty, WMIClass]),'WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
if oEnum.Next(1, FWbemObject, iValue) = 0 then
if not VarIsNull(FWbemObject.Properties_.Item(WMIProperty).Value) then
Result:=FWbemObject.Properties_.Item(WMIProperty).Value;
FWbemObject:=Unassigned;
end;
procedure TForm4.Button1Click(Sender: TObject);
var
X:string;
Y:string;
begin
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
X:=GetWMIstring('Win32_BIOS','SerialNumber');
Y:=GetWMIstring('Win32_PhysicalMedia','SerialNumber');
ShowMessage(X+';'+Y);
end;