ABCmo
ABCmo

Reputation: 237

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

I'm trying to get the time of launch of a running process. Is it possible to do in Windows, and how please?

Upvotes: 0

Views: 133

Answers (1)

TypeIA
TypeIA

Reputation: 17250

You can use the GetProcessTimes() function. Use GetCurrentProcess() to get a handle to the current process.

One of its arguments (lpCreationTime) is a pointer to a FILETIME struct which gets filled in with the time the process was created.

You can then use FileTimeToSystemTime() to convert the FILETIME struct to a SYSTEMTIME struct which has calendar day/month/year and hour/minute/second fields.

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

Upvotes: 1

Related Questions