|
-
Aug 2nd, 2002, 02:20 PM
#1
Thread Starter
Member
Find out how long a program has been running
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
-
Aug 2nd, 2002, 10:19 PM
#2
Hyperactive Member
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
-
Aug 3rd, 2002, 07:06 AM
#3
Thread Starter
Member
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.
-
Aug 3rd, 2002, 05:06 PM
#4
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
-
Aug 6th, 2002, 04:29 PM
#5
Frenzied Member
Handle to the process gives you:
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
Use DateDiff to get the up time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|