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
Printable View
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
One way would be to use the GetTickCount api call. GetTickCount returns the number of milliseconds since the machine was booted.
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:Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Code:Dim lRtrn1&, lRtrn2&
lRtrn1=GetTickCount
'/
'/...
'/
lRtrn2=GetTickCount
msgbox lRtrn2-lRtrn1 & " milliseconds between calls!"
td.
just read what you actually asked!!!!
Working on an answer now.
td.
'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
'
nah, Lateshnair wants to find out how long another app has been running (e.g. Winword.exe)
I'm looking at GetProcessTimes...
td.
Me too!
Ooops!
just read what you actually asked!!!!
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.
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