function GetWMIProperty(WMIType, 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_'+ WMIType);
Enum:=IEnumVariant(IUnknown(Objs._NewEnum));
Enum.Reset;
while Enum.Next(1,Obj,C)=s_ok do
begin
Obj:=Obj.Properties_.Item(WMIProperty,0).Value;
form1.Memo1.Lines.Add(obj);
if VarIsArray(Obj) then Result:=Obj[0]
else Result:=Obj;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:String;
begin
s:=getwmiproperty('LogicalDisk','Name');
showmessage(s);
end;
请参考http://blog.csdn.net/yuzl32/archive/2007/03/12/1527384.aspx