No announcement yet.

Is This App Running?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Semen Matusovski
    Larry --
    If it's interesting, you can test one fragment from my "hot reserve".
    This code is based on undocumented functions in User32.Dll.

    #Compile Exe
    #Dim All
    #Register None
    #Include "Win32Api.Inc"
    $AppTitle = "Ltr" ' <--------------- Change me
    Declare Function MySubCall(hWnd As Long) As Long
    Function PbMain
    Dim hWnd As Long, hUser32 As Long
       hWnd = FindWindow (ByVal %Null, $AppTitle)
       If IsWindow(hWnd) = %False Then Exit Do
       hUser32 = GetModuleHandle("user32.dll")
       If hUser32 = 0 Then Exit Do
       Dim IsHungAppWindow As Dword, IsHungThread As Dword
       Dim os As OSVERSIONINFO
       os.dwOSVersionInfoSize = SizeOf(os)
       GetVersionEx ByVal VarPtr(os)
       Dim IsHung As Long
       If IsTrue(os.dwPlatformId = %VER_PLATFORM_WIN32_NT) Then
          IsHungAppWindow = GetProcAddress(hUser32, "IsHungAppWindow")
          If IsHungAppWindow = 0 Then Exit Do
          Call Dword IsHungAppWindow Using MySubCall(100) To IsHung
          IsHungThread = GetProcAddress(hUser32, "IsHungThread")
          If IsHungThread = 0 Then Exit Do
          Dim ThreadId As Long
          ThreadId = GetWindowThreadProcessId(hWnd, %Null)
          Call Dword IsHungThread Using MySubCall(ThreadId) To IsHung
       End If
       If IsTrue(IsHung) Then IsHung = 2 Else IsHung = 1
       Exit Do
    Select Case IsHung
      Case 0: MsgBox "Not found"
      Case 1: MsgBox "Running"
      Case 2: MsgBox "Not responding"
    End Select
    End Function

    Leave a comment:

  • Lance Edmonds
    I think the most common method is to use SendMessageTimeout() and if the app does not respond after a reasonable period, the app is considered as "frozen" or "not responding".

    It is interesting to note that if one app hogs the CPU, the others face CPU starvation, and sometimes become labeled by Task Manager as "Not responding", and then will come back to life again. Essentially, determining if an app has really frozen is not an exact science.

    Another way to approach the problem (since you are using NT) could be to write the app as an NT Service, and let NT do the monitoring, and optionally notify and/or reboot if the app fails.

    There is some example code in the Source Code forum showing how to create an NT service.

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Larry Westrick
    Guest started a topic Is This App Running?

    Is This App Running?

    Does anyone know how to detect if an application is 'Running'? The NT Task Manager lists all Apps and if they are 'Running' or 'Not Responding'.

    I would like to create a program that starts an App. and then monitors it so that if it hangs, posts an error or whatever the App. can be stopped and restarted.