#include
#include
#include "winbase1.h"//含有GetSystemTimes函数的winbase.h移动到了原文件目录下
double ProgTime[2];
double KernTime[2];
double UserTime[2];
void cpucasement(){
SYSTEM_INFO systeminfo;
GetSystemInfo(&systeminfo);
printf("系统:\t\tWindows\n");
printf("处理器个数:\t%d\n",systeminfo.dwNumberOfProcessors);
printf("处理器掩码:\t%d\n",systeminfo.dwActiveProcessorMask);
printf("处理器类型:\t%d\n",systeminfo.dwProcessorType);
printf("处理器等级:\t%d\n",systeminfo.wProcessorLevel);
printf("处理器版本:\t%d\n",systeminfo.wProcessorRevision);}
void GetDisk(){
double a[4],b[4],c[4];
GetDiskFreeSpaceEx("C:",a,b,c);
GetDiskFreeSpaceEx("D:",a+1,b+1,c+1);
GetDiskFreeSpaceEx("E:",a+2,b+2,c+2);
printf("硬盘利用率:\t%.3lf%%\n",(1-(c[0]+c[1]+c[2])/(b[0]+b[1]+b[2]))*100);}
double FileTimeToDouble(FILETIME*q){
double w;
w=(double)(q->dwHighDateTime*4.284967296E9)+(double)(q->dwLowDateTime);
return w;
}
int GetTime(){
int jud[2]={0},i=0;
FILETIME a,b,c;
for(i=0;i<2;i++){
jud[i]=GetSystemTimes(&a,&b,&c);
ProgTime[i]=FileTimeToDouble(&a);
KernTime[i]=FileTimeToDouble(&b);
UserTime[i]=FileTimeToDouble(&c);
Sleep(10);}
return jud[0]&&jud[1];
}
int main(){
int jud=1;
cpucasement();
GetDisk();
while(jud){
jud=GetTime();
printf("cpu利用率为:%.2lf",1-(ProgTime[1]-ProgTime[0])/(KernTime[1]-KernTime[0]+UserTime[1]-UserTime[0]));
}
return 0;}