你可以搜索MS的一个The Portable Script Center的文档 里面囊括了几乎所有的例子 参考procedure TfrmMain.GetCpuInfo(); var Locator,WMI,RET,Tmp: OleVariant; Enum: IEnumVariant; Value: Cardinal; iCount,i:Integer; tmpstr:string; cpupercentage:double; begin try iCount:=0; cpupercentage:=0; for i:=0 to iCpuCount-1 do begin CpuInfoArray[i].ClockSpeed:=''; CpuInfoArray[i].Manufacturer:=''; CpuInfoArray[i].ProcessorId:=''; CpuInfoArray[i].Percentage:=''; CpuInfoArray[i].WarmInfo:=0; end; Locator:=CreateOleObject('WbemScripting.SWbemLocator'); WMI:=Locator.ConnectServer('.', '', '', ''); Ret:=WMI.ExecQuery('select * from Win32_Processor'); Enum:=IUnknown(RET._NewEnum) as IEnumVariant; while(Enum.Next(1,Tmp,Value)=S_OK) do begin CpuInfoArray[iCount].ClockSpeed :=NullDef(Tmp.MaxClockSpeed,'0'); CpuInfoArray[iCount].ClockSpeed :=CpuInfoArray[iCount].ClockSpeed+'MHZ'; CpuInfoArray[iCount].Manufacturer :=NullDef(Tmp.Manufacturer,'0'); CpuInfoArray[iCount].ProcessorId :=NullDef(Tmp.ProcessorId,'0'); CpuInfoArray[iCount].Percentage :=NullDef(Tmp.LoadPercentage,'0'); cpupercentage:=cpupercentage+StrToIntDef(CpuInfoArray[iCount].Percentage,0); iCount:=iCount+1; Tmp:=Null; end; if icount>0 then begin if (cpuPercentage/icount)>=FzArr[fzCPU] then begin tmpstr:=ComputerInfo+' CPU 使用率为'+floatTostr(Round(cpuPercentage/icount))+'%超出阀值'; AddWarnInfo(now,tmpstr); memo1.Lines.Add(tmpstr); end; end; iCpuCount:=iCount; except end; end;
http://blog.csdn.net/zhoufoxcn/archive/2008/01/14/2042697.aspx
var
Locator,WMI,RET,Tmp: OleVariant;
Enum: IEnumVariant;
Value: Cardinal; iCount,i:Integer;
tmpstr:string; cpupercentage:double;
begin
try
iCount:=0;
cpupercentage:=0; for i:=0 to iCpuCount-1 do
begin
CpuInfoArray[i].ClockSpeed:='';
CpuInfoArray[i].Manufacturer:='';
CpuInfoArray[i].ProcessorId:='';
CpuInfoArray[i].Percentage:='';
CpuInfoArray[i].WarmInfo:=0;
end; Locator:=CreateOleObject('WbemScripting.SWbemLocator');
WMI:=Locator.ConnectServer('.', '', '', '');
Ret:=WMI.ExecQuery('select * from Win32_Processor');
Enum:=IUnknown(RET._NewEnum) as IEnumVariant;
while(Enum.Next(1,Tmp,Value)=S_OK) do
begin
CpuInfoArray[iCount].ClockSpeed :=NullDef(Tmp.MaxClockSpeed,'0');
CpuInfoArray[iCount].ClockSpeed :=CpuInfoArray[iCount].ClockSpeed+'MHZ';
CpuInfoArray[iCount].Manufacturer :=NullDef(Tmp.Manufacturer,'0');
CpuInfoArray[iCount].ProcessorId :=NullDef(Tmp.ProcessorId,'0');
CpuInfoArray[iCount].Percentage :=NullDef(Tmp.LoadPercentage,'0'); cpupercentage:=cpupercentage+StrToIntDef(CpuInfoArray[iCount].Percentage,0); iCount:=iCount+1;
Tmp:=Null;
end;
if icount>0 then
begin
if (cpuPercentage/icount)>=FzArr[fzCPU] then
begin
tmpstr:=ComputerInfo+' CPU 使用率为'+floatTostr(Round(cpuPercentage/icount))+'%超出阀值';
AddWarnInfo(now,tmpstr);
memo1.Lines.Add(tmpstr);
end;
end; iCpuCount:=iCount;
except
end;
end;