Private Declare PtrSafe Function GetProcessTimes Lib "kernel32" (ByVal hProcess As LongPtr, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Private Declare PtrSafe Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare PtrSafe Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPtr
Private Declare PtrSafe Sub CloseHandle Lib "kernel32" (ByVal aObj As LongPtr)
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Function ProcessStartTime(ByVal Pid As Long) As Date
Const PROCESS_QUERY_LIMITED_INFORMATION = &H1000
Dim D As FILETIME, st As FILETIME
Dim h As LongPtr, r As SYSTEMTIME
h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, Pid)
If h <> 0 Then
GetProcessTimes h, st, D, D, D
CloseHandle h
FileTimeToLocalFileTime st, D
FileTimeToSystemTime D, r
ProcessStartTime = DateSerial(r.wYear, r.wMonth, r.wDay) + TimeSerial(r.wHour, r.wMinute, r.wSecond)
End If
End Function