Delphi Base

WindSon

导航

delphi Wmi 获取操作系统信息

uses ActiveX, ComObj;

function GetWMIProperty(WMIProperty: string): string;
var
Wmi, Objs, Obj: OleVariant;
Enum: IEnumVariant;
C: Cardinal;
begin
Wmi:= CreateOleObject('WbemScripting.SWbemLocator');
Objs := Wmi.ConnectServer('.','root/cimv2').ExecQuery('Select * from Win32_OperatingSystem');
Enum := IEnumVariant(IUnknown(Objs._NewEnum));
Enum.Reset;
Enum.Next(1, Obj, C);
Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
Result := Obj;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

Memo1.Text :=GetWMIProperty('Caption')+GetWMIProperty('Version');
end;

 

posted on 2020-03-16 17:46  windsonvip  阅读(633)  评论(0编辑  收藏  举报