WinBatch Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mjwillyone on August 16, 2021, 04:02:52 pm

Title: Non-Responsive Program
Post by: mjwillyone 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?
Title: Re: Non-Responsive Program
Post by: td 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 (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.
Title: Re: Non-Responsive Program
Post by: stanl on August 17, 2021, 03:53:13 am
not a better idea, but could probably adapt this to CLR:


https://techibee.com/powershell/powershell-find-applications-in-not-responding-state-in-task-manager/2226

Title: Re: Non-Responsive Program
Post by: td 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)
Title: Re: Non-Responsive Program
Post by: mjwillyone 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
Title: Re: Non-Responsive Program
Post by: td 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.