T
takashiki
Unregistered / Unconfirmed
GUEST, unregistred user!
//uses ActiveX, ComObj;
//这个函数使用了WMI,而且只获取第一个硬件/软件设置的信息。
//用户可以根据需要自行修改。
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;
Enum.Next(1,Obj,C);
//需要更多的信息请使用循环
Obj:=Obj.Properties_.Item(WMIProperty,0).Value;
if VarIsArray(Obj) then
Result:=Obj[0]
else
Result:=Obj;
end;
函数的调用:
procedure TForm1.btn6Click(Sender: TObject);
begin
ShowMessage(GetWMIProperty('BIOS','BIOSVersion'));
//获得BIOS版本
ShowMessage(GetWMIProperty('DiskDrive','PNPDeviceID'));
//获得第一块硬盘的设备标示
ShowMessage(GetWMIProperty('Processor','ProcessorId'));
//获得CPUID。
end;
其他功能可以由用户自己完成,因为WMI内容太多了,我不愿贴出太多。
//这个函数使用了WMI,而且只获取第一个硬件/软件设置的信息。
//用户可以根据需要自行修改。
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;
Enum.Next(1,Obj,C);
//需要更多的信息请使用循环
Obj:=Obj.Properties_.Item(WMIProperty,0).Value;
if VarIsArray(Obj) then
Result:=Obj[0]
else
Result:=Obj;
end;
函数的调用:
procedure TForm1.btn6Click(Sender: TObject);
begin
ShowMessage(GetWMIProperty('BIOS','BIOSVersion'));
//获得BIOS版本
ShowMessage(GetWMIProperty('DiskDrive','PNPDeviceID'));
//获得第一块硬盘的设备标示
ShowMessage(GetWMIProperty('Processor','ProcessorId'));
//获得CPUID。
end;
其他功能可以由用户自己完成,因为WMI内容太多了,我不愿贴出太多。