Hi all,
Is there an API where you can find out how long a program/process has been running? I know you can use GetTickCount for how long Windows has been active, and was wondering if there was a similar API call for all programs/processes?
Thanks
Printable View
Hi all,
Is there an API where you can find out how long a program/process has been running? I know you can use GetTickCount for how long Windows has been active, and was wondering if there was a similar API call for all programs/processes?
Thanks
I'm not sure. As an alternative, you could store the time when your program starts, and then compare that to the current time..
Code:Option Explicit
Dim ProgStartTime As Date
Private Sub Command1_Click()
MsgBox DateDiff("s", ProgStartTime , Now)
End Sub
Private Sub Form_Load()
theTime = Now
End Sub
Hi,
Thanks but I'm trying to find out how long a different app (which may have been running even before my app starts) has been running.
If you have a handle to the thread you can use GetThreadTimes:
VB Code:
Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Declare Function GetThreadTimes Lib "kernel32" (ByVal hThread As Long, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Hope this helps,
Duncan
Handle to the process gives you:
Use DateDiff to get the up time.Code: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 Declare Function GetProcessTimes Lib "kernel32" (ByVal hProcess As Long, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
Dim FT0 As FILETIME, FT1 As FILETIME, ST As SYSTEMTIME
GetProcessTimes GetCurrentProcess, FT1, FT0, FT0, FT0
FileTimeToLocalFileTime FT1, FT1
FileTimeToSystemTime FT1, ST
MsgBox "This program was started at " + CStr(ST.wHour) + ":" + CStr(ST.wMinute) + "." + CStr(ST.wSecond) + " on " + CStr(ST.wMonth) + "/" + CStr(ST.wDay) + "/" + CStr(ST.wYear)
End Sub