根據網上的代碼稍作修改。需要先安裝JwAPI
unit CPUUsage;interfaceuses Windows, JwaNative;function GetCPURate: Byte;implementationvar FOldIdleTime: LARGE_INTEGER; FOldSystemTime: LARGE_INTEGER;function GetCPURate: Byte;var PerfInfo: TSystemPerformanceInformation; TimeInfo: TSystemTimeOfDayInformation; BaseInfo: TSystemBasicInformation; IdleTime: INT64; SystemTime: INT64;begin Result := 0; if NtQuerySystemInformation(SystemTimeOfDayInformation, @TimeInfo, SizeOf(TimeInfo), nil) <> NO_ERROR then Exit; if NtQuerySystemInformation(SystemPerformanceInformation, @PerfInfo, SizeOf(PerfInfo), nil) <> NO_ERROR then Exit; if NtQuerySystemInformation(SystemBasicInformation, @BaseInfo, SizeOf(BaseInfo), nil) <> NO_ERROR then Exit; if (FOldIdleTime.QuadPart <> 0) and (BaseInfo.NumberProcessors <> 0) then begin IdleTime := PerfInfo.IdleTime.QuadPart - FOldIdleTime.QuadPart; SystemTime := TimeInfo.CurrentTime.QuadPart - FOldSystemTime.QuadPart; if SystemTime <> 0 then Result := Trunc(100.0 - (IdleTime / SystemTime) * 100.0 / BaseInfo.NumberProcessors); end; FOldIdleTime := PerfInfo.IdleTime; FOldSystemTime := TimeInfo.CurrentTime;end;end.