如何获取正在运行的进程的启动时间

How do I get time of launch of a running process?

本文关键字:运行 进程 启动 时间 何获取 获取      更新时间:2023-10-16

我正在尝试获取正在运行的进程的启动时间。是否可以在Windows中执行此操作,请如何?

您可以使用 GetProcessTimes() 函数。使用 GetCurrentProcess() 获取当前进程的句柄。

它的一个参数(lpCreationTime)是一个指向FILETIME结构的指针,该结构被填充到进程的创建时间。

然后,您可以使用 FileTimeToSystemTime() 将FILETIME结构转换为具有日历日/月/年和小时/分钟/秒字段的SYSTEMTIME结构。

HANDLE hCurrentProcess = GetCurrentProcess();
FILETIME creationTime;
FILETIME exitTime;
FILETIME kernelTime;
FILETIME userTime;
GetProcessTimes(hCurrentProcess, &creationTime,
    &exitTime, &kernelTime, &userTime);
SYSTEMTIME systemTime;
FileTimeToSystemTime(&creationTime, &systemTime);
// systemTime now holds the calendar date/time the
// current process was created