|
-
Nov 18th, 2000, 07:39 AM
#1
Thread Starter
New Member
Hello friends,
HOw can I find out since how long an application is being running, LIke if MSword is running how will i find out since when it is running, i mean time.
Thanks
Latesh
-
Nov 18th, 2000, 07:47 AM
#2
Hyperactive Member
One way would be to use the GetTickCount api call. GetTickCount returns the number of milliseconds since the machine was booted.
Code:
Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
When your app first loads make the call. Then at any point in the future, make the call again. Second - First equals you app time in milliseconds.
Code:
Dim lRtrn1&, lRtrn2&
lRtrn1=GetTickCount
'/
'/...
'/
lRtrn2=GetTickCount
msgbox lRtrn2-lRtrn1 & " milliseconds between calls!"
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 18th, 2000, 07:54 AM
#3
Hyperactive Member
Ooops!
just read what you actually asked!!!!
Working on an answer now.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 18th, 2000, 08:32 AM
#4
_______
<?>
'
Code:
'how long has my app been running expressed in seconds
Option Explicit
Public myStart As Date, myEnd As Date
Public Function CheckTime(mys As Date, mye As Date) As String
Dim sHowLong As String
sHowLong = DateDiff("s", mye, mys)
MsgBox "Your program was started " & sHowLong & " seconds ago."
End Function
Private Sub Command1_Click()
myEnd = Now
Call CheckTime(myEnd, myStart)
End Sub
Private Sub Form_Load()
'get the time you started your application
myStart = Now
End Sub
'
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 18th, 2000, 08:47 AM
#5
Hyperactive Member
nah, Lateshnair wants to find out how long another app has been running (e.g. Winword.exe)
I'm looking at GetProcessTimes...
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 18th, 2000, 08:53 AM
#6
_______
<?>
Me too!
Ooops!
just read what you actually asked!!!!
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 18th, 2000, 09:21 AM
#7
Hyperactive Member
This should be what you need.
Code:
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetProcessTimes Lib "kernel32" (ByVal hProcess As Long, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
'/ PROCESS_QUERY_INFORMATION
Const PROCESS_VM_READ = &H10
Const PROCESS_QUERY_INFORMATION = &H400
'/
Public 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
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Function ProcessFromHwnd(ByVal hWnd& ) As Long
Dim l&, lPID&
On Error Resume Next
l = GetWindowThreadProcessId(hWnd, lPID)
ProcessFromHwnd = lPID
End Function
Private Sub main()
Dim s$, hWnd&, lPID&, lRtrn&, lOpenProcess&
Dim ft1 As FILETIME, ft2 As FILETIME, st1 As SYSTEMTIME
s = "Microsoft Word - Document1" '/ obviously you could place whatever here.
hWnd = FindWindow(vbNullString, s) '/ we go on window name. Alt, we could go on class name.
lPID = ProcessFromHwnd(hWnd) '/ processid
lOpenProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0&, lPID) '/ open handle to process. Need to use PROCESS_QUERY_INFORMATION for GetProcessTimes to work (according to the docs)
lRtrn = GetProcessTimes(lOpenProcess, ft1, ft2, ft2, ft2) '/ we're not bother about the last three
If lRtrn > 0 Then
FileTimeToLocalFileTime ft1, ft1
FileTimeToSystemTime ft1, st1
MsgBox "Process started at " & CStr(st1.wHour) & ":" + CStr(st1.wMinute) & "." & CStr(st1.wSecond) & " on " & CStr(st1.wMonth) & "/" & CStr(st1.wDay) & "/" & CStr(st1.wYear)
Else
'/ something went wrong!
'/ GetProcessTimes sets GetLastError if you need it.
End If
'/
CloseHandle lOpenProcess '/ clearup the open handle
End Sub
Hope this helps
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 20th, 2000, 11:23 AM
#8
Thread Starter
New Member
Thank guys
It was very kind of u guys for replying my query.
I'll test this code and let u know if it really satisfy my needs.
thanks
regards
Latesh
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
|