gpt4 book ai didi

c++ - 如何获得正在运行的进程的启动时间?

转载 作者:行者123 更新时间:2023-11-28 07:04:11 26 4
gpt4 key购买 nike

我正在尝试获取正在运行的进程的启动时间。是否可以在 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

关于c++ - 如何获得正在运行的进程的启动时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21997820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com