Results 1 to 8 of 8

Thread: How do i get any application tick time??

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Bangalore
    Posts
    9

    Exclamation

    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

  2. #2
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  3. #3
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362

    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.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    '
    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

  5. #5
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  7. #7
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Bangalore
    Posts
    9

    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
  •  



Click Here to Expand Forum to Full Width