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;

 

上一篇:Java 枚举(enum)类型详解


下一篇:Python--枚举