#include "windows.h"
#include "tlhelp32.h"
#include "iostream.h"
void main(int argc, char* argv[]) {
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 pe;
ZeroMemory(&pe,sizeof(pe));
pe.dwSize=sizeof(pe);
BOOL bMore=Process32First(hSnapshot,&pe);
while (bMore) {
HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pe.th32ProcessID);
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
GetProcessTimes(hProcess,&CreationTime,&ExitTime,&KernelTime,&UserTime);
SYSTEMTIME ProCreationTime,ftKernelTime,ftUserTime,LocalTime;
FileTimeToSystemTime(&CreationTime,&ProCreationTime);//转换为系统时间
FileTimeToSystemTime(&KernelTime,&ftKernelTime);//转换为系统时间
FileTimeToSystemTime(&UserTime,&ftUserTime);//转换为系统时间
GetSystemTime(&LocalTime);//获取系统时间
int time1,time2;
time1=ftKernelTime.wHour*3600000+ftKernelTime.wMinute*60000+ftKernelTime.wSecond*1000+ftKernelTime.wMilliseconds;//计算核心态时间
time2=ftUserTime.wHour*3600000+ftUserTime.wMinute*60000+ftUserTime.wSecond*1000+ftUserTime.wMilliseconds;//计算用户态时间
if (hProcess!=NULL) {
cout<<"process ID:"<<pe.th32ProcessID<<".exe file:"<<pe.szExeFile<<" "<<endl
<<"启动时间:"<<(ProCreationTime.wHour+8)%24/*将格林尼治时间转换为北京时间*/<<":"<<ProCreationTime.wMinute<<":"<<ProCreationTime.wSecond<<":"<<ProCreationTime.wMilliseconds<<endl
<<"核心态时间:"<<time1<<" milliseconds;"<<endl
<<"用户态时间:"<<time2<<" milliseconds"<<endl;
cout<<endl;
CloseHandle(hProcess);
}
bMore=Process32Next(hSnapshot,&pe);
}
system("pause");
}
评论2
最新资源