viewpoint-particle

Author Topic: Non-Responsive Program  (Read 269 times)

mjwillyone

  • Newbie
  • *
  • Posts: 49
Non-Responsive Program
« on: August 16, 2021, 04:02:52 pm »
Once in a while I have a windows program that I am going to use keystrokes, etc to run reports from that, when opened, reads "Not Responding" as part of the file name at the top of the open window (see attached image.)

Is there a way that Winbatch could test for such a state?

td

  • Tech Support
  • *****
  • Posts: 3947
    • WinBatch
Re: Non-Responsive Program
« Reply #1 on: August 16, 2021, 05:16:41 pm »
You could use the WIL CLR hosting and the FCL's "System.Diagnostics.Process" class.  The class has a "Responding" property that returns false(0) when the process UI is not responding.

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.responding?redirectedfrom=MSDN&view=netframework-4.8#System_Diagnostics_Process_Responding

Tomorrow I will try and set aside some time to put together an example unless someone beats me to it or comes up with a better idea.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 1572
Re: Non-Responsive Program
« Reply #2 on: August 17, 2021, 03:53:13 am »

td

  • Tech Support
  • *****
  • Posts: 3947
    • WinBatch
Re: Non-Responsive Program
« Reply #3 on: August 17, 2021, 06:36:13 am »
To target a single application:

Code: Winbatch
; Load needed assembly and class
ObjectClrOption("useany","System")
objProcess = ObjectClrNew("System.Diagnostics.Process")

strText = "Firefox is OK"
strProcName = "firefox"   ; Process to check
aProcs = objProcess.GetProcessesByName(strProcName)

; Check all processes with the targeted name
nProcMax =  ArrInfo(aProcs, 1) - 1
for  i = 0 to  nProcMax
   if !aProcs[i].Responding()
      strText = "Found unresponsive process"
      break
   endif
next

; Do something with the newly gained information.
Message('FireFox Check', strText)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mjwillyone

  • Newbie
  • *
  • Posts: 49
Re: Non-Responsive Program
« Reply #4 on: August 20, 2021, 05:13:42 am »
Thank you, TD!

So, I would alter the strProcName to my own application and the strText to what fits.  Is that correct?  And, is the strProcName the window name or the title of the exe?

Mike

td

  • Tech Support
  • *****
  • Posts: 3947
    • WinBatch
Re: Non-Responsive Program
« Reply #5 on: August 20, 2021, 06:24:06 am »
On newer versions of Windows MSFT has an in my opinion a rather strange way of identifying processes by name. Generally, but not always the name is the root name of the executable file that contains the application machine instructions. One way to check is to look for the application in Task Manager. That name will usually work if you don't include the parenthesis and contents after the name.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade