liufeng24(流枫) 老兄,我没怎么看懂你的意思,NtQuerySystemInformation这个函数那里可以找到?
另:GetProcessTimes不能取到cpu时间,
BOOL GetProcessTimes(
HANDLE hProcess, // specifies the process of interest
LPFILETIME lpCreationTime, // when the process was created
LPFILETIME lpExitTime, // when the process exited
LPFILETIME lpKernelTime, // time the process has spent in kernel
// mode
LPFILETIME lpUserTime // time the process has spent in user mode
);
// get system time
status = NtQuerySystemInformation(3,&SysTimeInfo,sizeof(SysTimeInfo),0);
if (status!=NO_ERROR)
{
MessageBox("failed to get system time!");
}
// get cpu idle time
status = NtQuerySystemInformation(2,&SysPerfInfo,sizeof(SysPerfInfo),NULL);
if (status != NO_ERROR)
{
MessageBox("failed to get cpu time");
}
if (liOldIdleTime.QuadPart != 0)
{
// new cpu Time = NewTime - OldTime
dbCpuIdleTime =LI64ToDouble(SysPerfInfo.liIdleTime)-LI64ToDouble(liOldIdleTime);
dbSysTime =LI64ToDouble(SysTimeInfo.liKeSystemTime)-LI64ToDouble(liOldSysTime);
//get cpu usage
unCpuUsage=100 - 100*(dbCpuIdleTime/dbSysTime)/(double)SysBaseInfo.bKeNumberProcessors+0.5;
}
//if cpu usage ==0% then shutdown os
if(bSetAuto&&(UINT)dbCpuIdleTime==0)
{
//MessageBox("shutdown os!");
ShutDown();
}
// store new cpu idle and system time
liOldIdleTime = SysPerfInfo.liIdleTime;
liOldSysTime = SysTimeInfo.liKeSystemTime;